.. This file is automatically generated. Do not edit this file directly. Google Cloud Storage Python Samples =============================================================================== This directory contains samples for Google Cloud Storage. `Google Cloud Storage`_ allows world-wide storage and retrieval of any amount of data at any time. .. _Google Cloud Storage: https://cloud.google.com/storage/docs Setup ------------------------------------------------------------------------------- Authentication ++++++++++++++ Authentication is typically done through `Application Default Credentials`_, which means you do not have to change the code to authenticate as long as your environment has credentials. You have a few options for setting up authentication: #. When running locally, use the `Google Cloud SDK`_ .. code-block:: bash gcloud auth application-default login #. When running on App Engine or Compute Engine, credentials are already set-up. However, you may need to configure your Compute Engine instance with `additional scopes`_. #. You can create a `Service Account key file`_. This file can be used to authenticate to Google Cloud Platform services from any environment. To use the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to the path to the key file, for example: .. code-block:: bash export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json .. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow .. _additional scopes: https://cloud.google.com/compute/docs/authentication#using .. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount Install Dependencies ++++++++++++++++++++ #. Install `pip`_ and `virtualenv`_ if you do not already have them. #. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. .. code-block:: bash $ virtualenv env $ source env/bin/activate #. Install the dependencies needed to run the samples. .. code-block:: bash $ pip install -r requirements.txt .. _pip: https://pip.pypa.io/ .. _virtualenv: https://virtualenv.pypa.io/ Samples ------------------------------------------------------------------------------- List Objects +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ To run this sample: .. code-block:: bash $ python list_objects.py usage: list_objects.py [-h] bucket Command-line sample application for listing all objects in a bucket using the Cloud Storage API. This sample is used on this page: https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples For more information, see the README.md under /storage. positional arguments: bucket Your Cloud Storage bucket. optional arguments: -h, --help show this help message and exit CRUD Objects +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ To run this sample: .. code-block:: bash $ python crud_object.py usage: crud_object.py [-h] [--reader READER] [--owner OWNER] filename bucket Application for uploading an object using the Cloud Storage API. This sample is used on this page: https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples For more information, see the README.md under /storage. positional arguments: filename The name of the file to upload bucket Your Cloud Storage bucket. optional arguments: -h, --help show this help message and exit --reader READER Your Cloud Storage bucket. --owner OWNER Your Cloud Storage bucket. Compose objects +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ To run this sample: .. code-block:: bash $ python compose_objects.py usage: compose_objects.py [-h] bucket destination sources [sources ...] Command-line sample application for composing objects using the Cloud Storage API. This sample is used on this page: https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples For more information, see the README.md under /storage. To run, create a least two sample files: $ echo "File 1" > file1.txt $ echo "File 2" > file2.txt Example invocation: $ python compose_objects.py my-bucket destination.txt file1.txt file2.txt positional arguments: bucket Your Cloud Storage bucket. destination Destination file name. sources Source files to compose. optional arguments: -h, --help show this help message and exit Customer-Supplied Encryption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ To run this sample: .. code-block:: bash $ python customer_supplied_keys.py usage: customer_supplied_keys.py [-h] bucket filename Command-line sample app demonstrating customer-supplied encryption keys. This sample demonstrates uploading an object while supplying an encryption key, retrieving that object's contents, and finally rotating that key to a new value. This sample is used on this page: https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples For more information, see the README.md under /storage. positional arguments: bucket Your Cloud Storage bucket. filename A file to upload and download. optional arguments: -h, --help show this help message and exit .. _Google Cloud SDK: https://cloud.google.com/sdk/