首页 > 解决方案 > 云函数 python 访问数据存储

问题描述

我正在寻找有关如何使用云函数 (python) 访问数据存储的教程或文档。

但是,似乎只有 nodejs 的教程。 https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastore 有人可以帮帮我吗?谢谢

标签: google-cloud-datastoregoogle-cloud-functions

解决方案


从 python 中的云函数访问数据存储不需要特殊设置。

您只需要像往常一样添加和使用数据存储客户端google-cloud-datastorerequirements.txt

要求.txt

# Function dependencies, for example:
# package>=version
google-cloud-datastore==1.8.0

主文件

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)

阅读更多:


推荐阅读