Google Cloud Endpoints Proto Datastore库
项目描述
endpoints-proto-datastore
此库旨在与Python版本的Google Cloud Endpoints一起使用。如果您想了解更多关于Google Cloud Endpoints的信息,请访问我们的文档。要运行这些示例中的每一个,您应该在项目中包含随此项目提供的endpoints_proto_datastore 文件夹。
通过扩展ndb.Model类和endpoints库的功能,此库允许您在API方法中直接与模型实体交互,而不是ProtoRPC请求。例如,而不是
@endpoints.method(MyModelMessage, MyModelMessage,
path='mymodel', http_method='POST',
name='mymodel.insert')
def InsertModel(self, request):
my_model = MyModel(attr1=request.attr1, attr2=request.attr2, ...)
transformed_model = DoSomething(my_model)
return MyModelMessage(attr1=transformed_model.attr1,
attr2=transformed_model.attr2, ...)
我们可以直接在请求中使用实体
@MyModel.method(path='mymodel', http_method='POST',
name='mymodel.insert')
def InsertModel(self, my_model):
return DoSomething(my_model)
而无需定义ProtoRPC消息类!
通过示例开始。
项目设置、安装和配置
要在您的App Engine应用程序中使用此库,您可以通过以下方式
下载endpoints_proto_datastore库并将其解压缩到您的App Engine应用程序的根目录中。例如,在基于Unix的机器上
(${GAE_PROJECT_ROOT})$ wget "https://github.com/GoogleCloudPlatform/"` `"endpoints-proto-datastore/blob/"` `"zipfile-branch/"` `"endpoints_proto_datastore.zip?raw=true" \ -O endpoints_proto_datastore.zip (${GAE_PROJECT_ROOT})$ unzip endpoints_proto_datastore.zip (${GAE_PROJECT_ROOT})$ rm endpoints_proto_datastore.zip
或者您可以通过将此存储库添加到您的项目作为git 子模块来保持最新状态
(${YOUR_GIT_ROOT})$ git submodule add https://github.com/GoogleCloudPlatform/endpoints-proto-datastore
这将在您的项目中创建一个名为 endpoints-proto-datastore 的整个项目文件夹。由于 Python 包 需要 __init__.py 文件才能正常导入,并且本项目的根目录并非旨在作为 Python 包,因此您需要将 endpoints-proto-datastore 添加到您的 Python 导入路径中。
最简单的方法是将以下几行添加到您的 appengine_config.py 文件中(如果文件还不存在,则创建该文件)
import os import sys ENDPOINTS_PROJECT_DIR = os.path.join(os.path.dirname(__file__), 'endpoints-proto-datastore') sys.path.append(ENDPOINTS_PROJECT_DIR)
注意:如果您的 App Engine 项目存储在您的 git 仓库中且不在根目录下,您可能需要为 endpoints-proto-datastore/endpoints_proto_datastore 目录创建一个符号链接并将其放置在 App Engine 项目的根目录下。
要安装 App Engine,请访问 开发环境 页面。
功能、问题和支持
测试
所有测试都封装在 endpoints_proto_datastore_test_runner.py 模块中。要运行测试,只需执行以下操作
$ python ${PATH_TO_TEST_RUNNER}/endpoints_proto_datastore_test_runner.py
此测试运行程序假定您已在路径上安装了 App Engine SDK 工具,并将使用 dev_appserver.py 脚本的位置来确定 SDK 的位置。例如,在基于 Unix 的系统上,它将等同于
$ dirname `readlink \`which dev_appserver.py\``
贡献更改
请参阅 CONTRIB.md
要为贡献的示例创建文档,请使用 pycco。例如
$ pycco example_name/main.py
许可
请参阅 LICENSE
注意:测试运行程序包含来自 Twisted 项目的某些代码,这些代码的 条款不同于 Apache 2.0。
项目详细信息
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
构建分布
散列 用于 endpoints_proto_datastore-0.10.0-py2-none-any.whl
算法 | 散列摘要 | |
---|---|---|
SHA256 | e72358a41d8cec1f9157e2f8137bf9e90c539608cdd6255cb79c2891a23fbdfa |
|
MD5 | e1af6294ea7e5ed30eb59e7b14f16f19 |
|
BLAKE2b-256 | 9a8e3525275c8a04f41a9f858b478e6b0e70c16c25cf444868298ff33979e851 |