问题
I am looking for a tutorial or document on how to access datastore using cloud functions (python).
However, it seems there is only tutorial for nodejs. https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastore Can anybody help me out? Thanks
回答1:
There are no special setup needed to access datastore from cloud functions in python.
You just need to add google-cloud-datastore
into requirements.txt
and use datastore client as usual.
requirements.txt
# 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)
Read more:
- Python Client for Google Cloud Datastore
- Setting Up Authentication for Server to Server Production Applications
来源:https://stackoverflow.com/questions/52078058/cloud-functions-python-to-access-datastore