LoginSignup
1
2

More than 5 years have passed since last update.

Python3 で Google Datastore のデータを削除 (Delete)

Last updated at Posted at 2018-05-18

Google Datastore にある次のデータを削除する方法です。
datastore_may1801.png

datastore_delete.py
#! /usr/bin/python
#
#   datastore_delete.py
#                       May/18/2018
# ------------------------------------------------------------------
from gcloud import datastore
import sys
# ------------------------------------------------------------------
def datastore_delete_proc(client,name):
    kind = 'Cities'
    key = client.key(kind,name)
    client.delete(key)
#
# ------------------------------------------------------------------
sys.stderr.write("*** start ***\n")
key_in = sys.argv[1]
#
print(key_in)
#
try:
    project_id = "my-project-aug-29-2016"
    client = datastore.Client(project_id)
except Exception as ee:
    sys.stderr.write("*** error *** in datastore.Client ***\n")
    sys.stderr.write(str(ee) + "\n")
#
datastore_delete_proc(client,key_in)
#
sys.stderr.write("*** end ***\n")
#
# ------------------------------------------------------------------

実行コマンド

export GOOGLE_APPLICATION_CREDENTIALS="/home/uchida/my_project_Aug-29-2016-7313bb6c3526.json"
#
./datastore_delete.py t0922
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2