Giter Club home page Giter Club logo

dsopz's Introduction

dsopz

DSOpz (Datastore Operationz) lets you manage your Google Cloud Datastore from command line.

CircleCI

Dsopz 2 Beta

This documentation is all about dsopz-1.x.x. I'm woking on dspoz2 :)

I'm not working on this any more

Features

  • Python API and command line
  • No dependencies (see below)
  • Uses Google Cloud Datastore JSON API
  • Export, import and delete data
  • GQL query
  • CSV exporter
  • Entity processors
    • You can update entities
    • Manage indexed properties
  • OAuth2 integrated
    • Installed apps
    • Service account

Gettings Started

  • Every command has --help
  • If namespace was not given, we will access your default one.
  • If kinds was not given, we will use all of them.

Install

# download from https://github.com/murer/dsopz/releases
easy_install dsopz.egg
dsopz version

module method

cd dsopz
python -m dsopz.dsopz version

Login

dsopz login

If you can't open a browser automatically to login you can use this command:

dsopz login-text

You can use GCE Service Account.

dsopz login-gce

Or regular Service Account

dsopz login-serviceaccount -f <json-file>

Scopes Required:

https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/datastore
https://www.googleapis.com/auth/userinfo.email

Console

dsopz console -d gae-projet -n namespace

Here you can type your gql like select *. Results are limited to 10, you can do -l 0 to turn it unlimited.

Export data

dsopz export -d gae-project -n namespace -k kind1 kind2 > entities.bak

GQL exporter

dsopz gql -d gae-project -n namespace -q 'select * from kind1' > entities.bak

Import data

cat entities.bak | dsopz import -d gae-project -n namespace -o upsert

You can import entities to another project or namespace.

Delete data

You need just a keys-only file to delete, and you can extract it using -o true while exporting

cat entities.bak | dsopz import -d gae-project -n namespace -o remove

Set indexed true or false

cat entities.bak | dsopz index -c col1 col2 -k kind2 kind2 -i true > processed.bak
cat processed.bak | dsopz import -d gae-project -n namespace -o upsert

This will generate processe.bak file with all entities from entities.bak which have changed col1 or col2 to indexed true. And upload it back to datastore

Updating, delete or create

We can process a entity file into another, incluiding, updating or removing entities.

cat entities.bak | dsopz map > procesed.bak 3<mapper.py

or

cat entities.bak | dsopz map > processed.bak 3<<-EOF
ent['properties']['desc'] = {'excludeFromIndexes': True, 'stringValue': 'changed'}
emit(ent)
EOF

dsopz/dsopz.py map reads entities file from stdin, and python code from custom pipe input 3. This python code is called for every entity witch can be accessed via ent variable. This code can call emit function multiple times with one or more entities to be printed to processed.bak.

Extract CSV from entities file

cat entities.bak | dsopz csv -k kind1 kind2 -c col1 col2 > entities.csv

As you can see, all commands use stdin or stdout to read/write entities. The file has one entity json per line. You can use | gzip and | gunzip to manage large amount of entities.

Entity File

This entity file used to pipe in or out these python commands has one json per file. Each json is a datastore entity just like Google Cloud Datastore returns. These entities does not have the partionId (namespace) information.

Processors

Processors is what you can do to manage your entities file before import (or delete) it back to datastore. You can actually write a processor to do whatever you want with a entities file, for example: send entities to somewhere, parse them into a csv, etc.

To write a processor, you will import processor and extend processor.Processor. Override resolve method to process self.block array of entities. Sample: processor_csv.py, processor_indexed.py

Devel

  • It is pure python 2.7
  • It does not need any dependency
    • Except by login-serviceaccount which requires pycryto to sign JWT

Running tests

You need to login

python -m dsopz.dsopz login

Now, you can start the tests on your project (required) and namespace (optional).

./test/test.sh your-project your-namespace

This test tries to clean up in the end.

dsopz's People

Contributors

feroult avatar luanpotter avatar matheusmr13 avatar murer avatar paulo-murer-movile avatar raonifn avatar renan-dextra avatar shaan7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dsopz's Issues

Prettify query output

Currently when running a query, the output comes out as a wall of text which is not easy to read through especially if the number of fields are large. I was wondering if we could print the output like you get in case of a PostgreSQL/MySQL db. The name of the fields would be printed in the first row and the values would then follow in separate rows. It would help in improving readability and will look more familiar to people coming from SQL background.

I have just started looking at the repo and I believe the necessary changes need to be made in the console.py file.

If the idea sounds good to you then I would like to proceed with making the necessary changes.

Error 403 usageLimits

I am getting the following error:

dsopz.http.Error: Status: 403 Forbidden {
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceeded",
    "message": "Daily Limit Exceeded. The quota will be reset at midnight Pacific Time (PT). You may monitor your quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/datastore/quotas?project=570403801115",
    "extendedHelp": "https://console.developers.google.com/apis/api/datastore/quotas?project=570403801115"
   }
  ],

I checked the quota on google cloud platform but I am not sure at which quota I should be looking.

crashes if columns are numeric

inside processor_csv.py it only checks for bool, it should probably check for int, long and float as well, otherwise processor attempts to call encode('UTF-8') on numeric types.

Daily Limit Exceeded

On running the command i get over quota error

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceeded",
    "message": "Daily Limit Exceeded. The quota will be reset at midnight Pacific Time (PT). You may monitor your quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/datastore/quotas?project=570403801115",
    "extendedHelp": "https://console.developers.google.com/apis/api/datastore/quotas?project=570403801115"
   }
  ],
  "code": 403,
  "message": "Daily Limit Exceeded. The quota will be reset at midnight Pacific Time (PT). You may monitor your quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/datastore/quotas?project=570403801115"
 }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.