Python 将json对象插入数据湖
我几乎没有python api端点可以在请求体中获取数据。每次api调用任何想法时,我都想将此数据插入/添加到azure datalake 示例api端点Python 将json对象插入数据湖,python,azure,stream,azure-data-lake,Python,Azure,Stream,Azure Data Lake,我几乎没有python api端点可以在请求体中获取数据。每次api调用任何想法时,我都想将此数据插入/添加到azure datalake 示例api端点 @main.route("/order/add", methods=["POST"]) def post_add_new_order(): data = request.json for key in data: if not typesModule.key_t
@main.route("/order/add", methods=["POST"])
def post_add_new_order():
data = request.json
for key in data:
if not typesModule.key_type_and_value_type_are_equal(key, data[key]):
return {"err": "One of the value types is incorrect"}
要将此数据插入azure data lake如果要在python包中将数据添加到azure data lake存储Gen1,我们可以使用包
azure datalake存储
来实现它
比如说
如果它对你有用的话,你可以吗
az login
az ad sp create-for-rbac -n 'Myapp' --skip-assignment
import json
import azure.datalake.store.lib as lib
from azure.datalake.store.core import AzureDLFileSystem
RESOURCE = 'https://datalake.azure.net/'
client_id = '42e0d***c4c522d988c4'
client_secret = 'Gbx2eK6****ClJDfQpIjoae:'
tenant = 'e4c9ab4e-bd27-40d5-8459-230ba2a757fb'
@main.route("/order/add", methods=["POST"])
def post_add_new_order():
data = request.get_json()
json_data = json.dumps(data).encode('utf-8')
adlCreds = lib.auth(tenant_id = tenant,
client_secret = client_secret,
client_id = client_id,
resource=RESOURCE)
adlsFileSystemClient = AzureDLFileSystem(adlCreds, store_name='testbowman')
# check if the file exist
if adlsFileSystemClient.access('/test/data.json'):
#append content
with adlsFileSystemClient.open(path='/test/data.json', mode='ab') as f:
f.write(json_data)
f.write(b'\r\n')
else:
#create file and write
with adlsFileSystemClient.open(path='/test/data.json', mode='wb') as f:
f.write(json_data)
f.write(b'\r\n')
return {'you sent' : data}