|
| 1 | +Python Client for Google Cloud Storage |
| 2 | +====================================== |
| 3 | + |
| 4 | + Python idiomatic client for `Google Cloud Storage`_ |
| 5 | + |
| 6 | +.. _Google Cloud Storage: https://cloud.google.com/storage/docs |
| 7 | + |
| 8 | +- `Homepage`_ |
| 9 | +- `API Documentation`_ |
| 10 | + |
| 11 | +.. _Homepage: https://googlecloudplatform.github.io/google-cloud-python/ |
| 12 | +.. _API Documentation: http://googlecloudplatform.github.io/google-cloud-python/ |
| 13 | + |
| 14 | +Quick Start |
| 15 | +----------- |
| 16 | + |
| 17 | +:: |
| 18 | + |
| 19 | + $ pip install --upgrade google-cloud-storage |
| 20 | + |
| 21 | +Authentication |
| 22 | +-------------- |
| 23 | + |
| 24 | +With ``google-cloud-python`` we try to make authentication as painless as |
| 25 | +possible. Check out the `Authentication section`_ in our documentation to |
| 26 | +learn more. You may also find the `authentication document`_ shared by all |
| 27 | +the ``google-cloud-*`` libraries to be helpful. |
| 28 | + |
| 29 | +.. _Authentication section: http://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html |
| 30 | +.. _authentication document: https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication |
| 31 | + |
| 32 | +Using the API |
| 33 | +------------- |
| 34 | + |
| 35 | +Google `Cloud Storage`_ (`Storage API docs`_) allows you to store data on |
| 36 | +Google infrastructure with very high reliability, performance and |
| 37 | +availability, and can be used to distribute large data objects to users |
| 38 | +via direct download. |
| 39 | + |
| 40 | +.. _Cloud Storage: https://cloud.google.com/storage/docs |
| 41 | +.. _Storage API docs: https://cloud.google.com/storage/docs/json_api/v1 |
| 42 | + |
| 43 | +See the ``google-cloud-python`` API `storage documentation`_ to learn how to |
| 44 | +connect to Cloud Storage using this Client Library. |
| 45 | + |
| 46 | +.. _storage documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/storage-client.html |
| 47 | + |
| 48 | +You need to create a Google Cloud Storage bucket to use this client library. |
| 49 | +Follow along with the `official Google Cloud Storage documentation`_ to learn |
| 50 | +how to create a bucket. |
| 51 | + |
| 52 | +.. _official Google Cloud Storage documentation: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets |
| 53 | + |
| 54 | +.. code:: python |
| 55 | +
|
| 56 | + from google.cloud import storage |
| 57 | + client = storage.Client() |
| 58 | + bucket = client.get_bucket('bucket-id-here') |
| 59 | + # Then do other things... |
| 60 | + blob = bucket.get_blob('remote/path/to/file.txt') |
| 61 | + print(blob.download_as_string()) |
| 62 | + blob.upload_from_string('New contents!') |
| 63 | + blob2 = bucket.blob('remote/path/storage.txt') |
| 64 | + blob2.upload_from_filename(filename='/local/path.txt') |
0 commit comments