本文介绍了云函数python访问数据存储区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找有关如何使用云功能(python)访问数据存储的教程或文档.
I am looking for a tutorial or document on how to access datastore using cloud functions (python).
但是,似乎只有nodejs教程. https://github.com/GoogleCloudPlatform/nodejs-docs-样品/树/母版/功能/数据存储有人可以帮我吗?谢谢
However, it seems there is only tutorial for nodejs.https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastoreCan anybody help me out?Thanks
推荐答案
无需特殊设置即可从python中的云函数访问数据存储.
There are no special setup needed to access datastore from cloud functions in python.
您只需将google-cloud-datastore
添加到requirements.txt
并照常使用数据存储区客户端.
You just need to add google-cloud-datastore
into requirements.txt
and use datastore client as usual.
# Function dependencies, for example:
# package>=version
google-cloud-datastore==1.8.0
main.py
from google.cloud import datastore
datastore_client = datastore.Client()
def foo(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values...
"""
query = datastore_client.query(kind=<KindName>)
data = query.fetch()
for e in data:
print(e)
了解更多:
- Google Cloud Datastore的Python客户端
- 设置服务器到服务器生产应用程序的身份验证
- Python Client for Google Cloud Datastore
- Setting Up Authentication for Server to Server Production Applications
Read more:
这篇关于云函数python访问数据存储区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!