云函数python访问数据存储区 [英] cloud functions python to access Datastore

查看:141
本文介绍了云函数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/datastore Can 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)

了解更多:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆