3

I have a .json local file and I want to upload it to google cloud storage using Python.

First note that my python script is not on app-engine, it's a simple script so I don't want to use the appengine API. Secondly, I read this tutorial and I think it is extremely unclear.

Hence, I am looking for an alternative API, maybe wrote by someone outside from Google, to help me upload my json file using my json credentials.

4

1 Answer 1

2

If you want to interact with google cloud storage services outside of the App Engine environment, you may use Gcloud (https://googlecloudplatform.github.io/gcloud-python/stable/) to do so.

You need a service account on your application as well as download the JSON credentials file. With those, once you install the proper packages, you'll be able to make queries as well as write data.

Here is an example of authenticating yourself to use the library:

from gcloud import datastore

# the location of the JSON file on your local machine
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/location/client_secret.json"


# project ID from the Developers Console
projectID = "THE_ID_OF_YOUR_PROJECT"

os.environ["GCLOUD_TESTS_PROJECT_ID"] = projectID
os.environ["GCLOUD_TESTS_DATASET_ID"] = projectID
client = datastore.Client(dataset_id=projectID)

Edit:

This library is for the following as per the docs here(https://github.com/GoogleCloudPlatform/gcloud-python):

This client supports the following Google Cloud Platform services:

Google Cloud Datastore
Google Cloud Storage
Google Cloud Pub/Sub
Google BigQuery
Google Cloud Resource Manager
Sign up to request clarification or add additional context in comments.

2 Comments

I asked about GCS (google cloud storage), not the Datastore.
github.com/GoogleCloudPlatform/gcloud-python and that's what I gave you. Don't be so quick to down vote :(. I just put Datastore there because that's what I used it for. It works on Google Cloud Storage too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.