问题描述
我正在Google托管的计算机引擎(默认)上使用Google的Datalab服务,并且我想调用Google数据存储区的API. 文档指向使用from google.appengine.ext import db
库.
I am working with Google's Datalab service, on a Google managed Computer engine(default), and I would like to call my Google Datastore's API. The documentation points to using the from google.appengine.ext import db
library.
但是当我在datalab代码块中执行此命令时,会得到ImportError: No module named appengine.ext
.
But when I execute this in a datalab code block I get ImportError: No module named appengine.ext
.
我意识到这很自然地意味着在Datalab计算引擎上未安装App Engine SDK ,我的问题是如何从Datalab笔记本访问我的数据存储"命名空间?
I realize that this likly means that the App Engine SDK is not installed on the Datalab compute engine, My quetion is how can I then access the My Datastore namespace from my Datalab notebook?
推荐答案
似乎我最好使用gcloud软件包.在我更新gcloud软件包之前,我看到他们能够更新文档,这是我使用的代码示例:
It seems that I was better off using the gcloud package. Seeing as I updated the gcloud package before they where able to update documentation this is an example of the code I used:
from gcloud import datastore
from gcloud.datastore.key import Key
from gcloud.datastore.entity import Entity
import datetime
client = datastore.Client('project_id','namespace')
key = client.key('kind_name')
entity = datastore.Entity(key=key)
entity['datetime'] = datetime.datetime.now()
entity['some_other_column'] = 1
query = datastore.Query(client,kind='kind_name')
for result in query.fetch():
print result
这篇关于来自Datalab的Google Datastore API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!