本文整理汇总了Python中google.cloud.datastore.Client方法的典型用法代码示例。如果您正苦于以下问题:Python datastore.Client方法的具体用法?Python datastore.Client怎么用?Python datastore.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.cloud.datastore
的用法示例。
在下文中一共展示了datastore.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_config
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def from_config(cls, config, creds=None):
"""Returns an initialized DatastoreAPI object.
Args:
config: common.ProjectConfig, the project configuration.
creds: auth.CloudCredentials, the credentials to use for client
authentication.
Returns:
An authenticated DatastoreAPI instance.
"""
if creds is None:
creds = auth.CloudCredentials(config, cls.SCOPES)
client = datastore.Client(
project=config.project, credentials=creds.get_credentials(cls.SCOPES))
return cls(config, client)
示例2: run_quickstart
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def run_quickstart():
# [START datastore_quickstart]
# Imports the Google Cloud client library
from google.cloud import datastore
# Instantiates a client
datastore_client = datastore.Client()
# The kind for the new entity
kind = 'Task'
# The name/ID for the new entity
name = 'sampletask1'
# The Cloud Datastore key for the new entity
task_key = datastore_client.key(kind, name)
# Prepares the new entity
task = datastore.Entity(key=task_key)
task['description'] = 'Buy milk'
# Saves the entity
datastore_client.put(task)
print('Saved {}: {}'.format(task.key.name, task['description']))
# [END datastore_quickstart]
示例3: GetDatastoreDeleteCredentials
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def GetDatastoreDeleteCredentials():
"""Returns credentials to datastore db."""
if FLAGS.google_datastore_deletion_keyfile.startswith('gs://'):
# Copy private keyfile to local disk
cp_cmd = [
'gsutil', 'cp', FLAGS.google_datastore_deletion_keyfile,
FLAGS.private_keyfile
]
vm_util.IssueCommand(cp_cmd)
credentials_path = FLAGS.private_keyfile
else:
credentials_path = FLAGS.google_datastore_deletion_keyfile
credentials = service_account.Credentials.from_service_account_file(
credentials_path,
scopes=datastore.client.Client.SCOPE,
)
return credentials
示例4: __init__
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def __init__(self, project_id, bucket_name):
"""Initialize client with project id and name of the storage bucket."""
self.project_id = project_id
self.bucket_name = bucket_name
self.client = storage.Client(project=project_id)
self.bucket = self.client.get_bucket(bucket_name)
示例5: __init__
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def __init__(self):
self.datastore_client = datastore.Client()
示例6: __init__
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def __init__(self, namespace=None):
self._logger = logging.getLogger("flask-blogging")
self._client = datastore.Client(namespace=namespace)
示例7: _make_ds_client
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def _make_ds_client(namespace):
emulator = bool(os.environ.get("DATASTORE_EMULATOR_HOST"))
if emulator:
client = datastore.Client(namespace=namespace, _http=requests.Session)
else:
client = datastore.Client(namespace=namespace)
return client
示例8: client_context
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def client_context(namespace):
client = ndb.Client()
context_manager = client.context(
cache_policy=False, legacy_data=False, namespace=namespace,
)
with context_manager as context:
yield context
示例9: _backend_setup
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def _backend_setup(self, server=True, *args, **kwargs):
"""
Args:
server (bool): Whether this is the client or a server
Raises:
TurbiniaException: When there are errors creating PSQ Queue
"""
log.debug(
'Setting up PSQ Task Manager requirements on project {0:s}'.format(
config.TURBINIA_PROJECT))
self.server_pubsub = turbinia_pubsub.TurbiniaPubSub(config.PUBSUB_TOPIC)
if server:
self.server_pubsub.setup_subscriber()
else:
self.server_pubsub.setup_publisher()
psq_publisher = pubsub.PublisherClient()
psq_subscriber = pubsub.SubscriberClient()
datastore_client = datastore.Client(project=config.TURBINIA_PROJECT)
try:
self.psq = psq.Queue(
psq_publisher, psq_subscriber, config.TURBINIA_PROJECT,
name=config.PSQ_TOPIC, storage=psq.DatastoreStorage(datastore_client))
except exceptions.GoogleCloudError as e:
msg = 'Error creating PSQ Queue: {0:s}'.format(str(e))
log.error(msg)
raise turbinia.TurbiniaException(msg)
示例10: __init__
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def __init__(self):
config.LoadConfig()
try:
self.client = datastore.Client(project=config.TURBINIA_PROJECT)
except EnvironmentError as e:
message = (
'Could not create Datastore client: {0!s}\n'
'Have you run $ gcloud auth application-default login?'.format(e))
raise TurbiniaException(message)
示例11: main
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def main(project_id):
client = datastore.Client(project_id)
for name, function in globals().iteritems():
if name in ('main', 'defaultdict') or not callable(function):
continue
print(name)
pprint(function(client))
print('\n-----------------\n')
示例12: create_client
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def create_client(project_id):
return datastore.Client(project_id)
# [END datastore_build_service]
# [START datastore_add_entity]
示例13: client
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def client():
client = datastore.Client(PROJECT)
yield client
# Delete anything created during the test.
with client.batch():
client.delete_multi(
[x.key for x in client.query(kind='Task').fetch()])
示例14: index
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def index():
ds = datastore.Client()
user_ip = request.remote_addr
# Keep only the first two octets of the IP address.
if is_ipv6(user_ip):
user_ip = ':'.join(user_ip.split(':')[:2])
else:
user_ip = '.'.join(user_ip.split('.')[:2])
entity = datastore.Entity(key=ds.key('visit'))
entity.update({
'user_ip': user_ip,
'timestamp': datetime.datetime.utcnow()
})
ds.put(entity)
query = ds.query(kind='visit', order=('-timestamp',))
results = []
for x in query.fetch(limit=10):
try:
results.append('Time: {timestamp} Addr: {user_ip}'.format(**x))
except KeyError:
print("Error with result format, skipping entry.")
output = 'Last 10 visits:\n{}'.format('\n'.join(results))
return output, 200, {'Content-Type': 'text/plain; charset=utf-8'}
# [END gae_flex_datastore_app]
示例15: homepage
# 需要导入模块: from google.cloud import datastore [as 别名]
# 或者: from google.cloud.datastore import Client [as 别名]
def homepage():
# Create a Cloud Datastore client.
datastore_client = datastore.Client()
# Use the Cloud Datastore client to fetch information from Datastore about
# each photo.
query = datastore_client.query(kind='Faces')
image_entities = list(query.fetch())
# Return a Jinja2 HTML template and pass in image_entities as a parameter.
return render_template('homepage.html', image_entities=image_entities)