你可以在google appengine之外使用GQL / Google DataStore吗?

时间:2014-08-27 21:00:36

标签: python google-app-engine google-cloud-datastore gql

我可以在我的本地python应用程序中使用GQl / DataStore吗?我知道在编写webapp时运行dev_appserver.py时我可以在本地使用它们但是现在我不想做任何与web相关的事情并且只使用我的普通pythonfile.py将它保留在本地,没有HTML接口。是否有可能做到这一点?

2 个答案:

答案 0 :(得分:1)

  

Remote API也可以在本地应用程序中使用。这将允许您编写使用App Engine的本地应用程序   服务和访问数据存储区。重要的是要注意使用   远程API将在您的应用程序上产生配额使用   存取。

     

开始之前,请确保将App Engine SDK添加到Python中   您的App Engine应用程序中启用了路径和远程API。该   以下示例显示了使用OAuth 2.0凭据进行配置   远程API:

from google.appengine.ext.remote_api import remote_api_stub
from helloworld import helloworld

remote_api_stub.ConfigureRemoteApiForOAuth('your_app_id.appspot.com',
                                           '/_ah/remote_api')

# Fetch the most recent 10 guestbook entries
entries = helloworld.Greeting.all().order("-date").fetch(10)
# Create our own guestbook entry
helloworld.Greeting(content="A greeting").put()

参考:https://cloud.google.com/appengine/docs/python/tools/remoteapi

答案 1 :(得分:0)

是的,可以通过App Engine之外的客户端库访问Cloud Datastore。它们运行在v1 API上,该API在Beta测试几年后刚刚进入GA(2016年8月16日)。

The Client Libraries可用于Python,Java,Go,Node.js,Ruby,甚至还有.NET。

您应该知道NDB支持的GQL语言变体与Cloud Datastore服务本身支持的有所不同。 NDB客户端库执行一些自己的自定义解析,可以将某些查询拆分为多个查询以发送到服务,并将结果与​​客户端组合。

阅读我们的GQL reference docs