Python Client for Google Cloud Storage

imageimageimage

Google Cloud Storage is a managed service for storing unstructured data. Cloud Storageallows world-wide storage and retrieval of any amount of data at any time. You can useCloud Storage for a range of scenarios including serving website content, storing datafor archival and disaster recovery, or distributing large data objects to users via direct download.

A comprehensive list of changes in each version may be found in theCHANGELOG.

Certain control plane and long-running operations for Cloud Storage (including Folderand Managed Folder operations) are supported via theStorage Control Client.TheStorage Control API creates one space to perform metadata-specific, control plane,and long-running operations apart from the Storage API.

Read more about the client libraries for Cloud APIs, including the olderGoogle APIs Client Libraries, inClient Libraries Explained.

Quick Start

In order to use this library, you first need to go through the following steps.A step-by-step guide may also be found inGet Started with Client Libraries.

  1. Select or create a Cloud Platform project.

  2. Enable billing for your project.

  3. Enable the Google Cloud Storage API.

  4. Setup Authentication.

Installation

Install this library in a virtual environment usingvenv.venv is a tool thatcreates isolated Python environments. These isolated environments can have separateversions of Python packages, which allows you to isolate one project’s dependenciesfrom the dependencies of other projects.

Withvenv, it’s possible to install this library without needing systeminstall permissions, and without clashing with the installed systemdependencies.

Code samples and snippets

Code samples and snippets live in thesamples/ folder.

Supported Python Versions

Our client libraries are compatible with all currentactive andmaintenance versions ofPython.

Python >= 3.7

Unsupported Python Versions

Python <= 3.6

If you are using anend-of-lifeversion of Python, we recommend that you update as soon as possible to an actively supported version.

Mac/Linux

python3 -m venv <your-env>source <your-env>/bin/activatepip install google-cloud-storage

Windows

py -m venv <your-env>.\<your-env>\Scripts\activatepip install google-cloud-storage

Tracing With OpenTelemetry

This is a PREVIEW FEATURE: Coverage and functionality are still in development and subject to change.

This library can be configured to useOpenTelemetry to generate traces on calls to Google Cloud Storage.For information on the benefits and utility of tracing, read theCloud Trace Overview.

To enable OpenTelemetry tracing in the Cloud Storage client, first install OpenTelemetry:

pip install google-cloud-storage[tracing]

Set theENABLE_GCS_PYTHON_CLIENT_OTEL_TRACES environment variable to selectively opt-in tracing for the Cloud Storage client:

export ENABLE_GCS_PYTHON_CLIENT_OTEL_TRACES=True

You will also need to tell OpenTelemetry which exporter to use. An example to export traces to Google Cloud Trace can be found below.

# Install the Google Cloud Trace exporter and propagator, however you can use any exporter of your choice.pip install opentelemetry-exporter-gcp-trace opentelemetry-propagator-gcp# [Optional] Install the OpenTelemetry Requests Instrumentation to trace the underlying HTTP requests.pip install opentelemetry-instrumentation-requests
from opentelemetry import tracefrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessorfrom opentelemetry.exporter.cloud_trace import CloudTraceSpanExportertracer_provider = TracerProvider()tracer_provider.add_span_processor(BatchSpanProcessor(CloudTraceSpanExporter()))trace.set_tracer_provider(tracer_provider)# Optional yet recommended to instrument the requests HTTP libraryfrom opentelemetry.instrumentation.requests import RequestsInstrumentorRequestsInstrumentor().instrument(tracer_provider=tracer_provider)

In this example, tracing data will be published to theGoogle Cloud Trace console.Tracing is most effective when many libraries are instrumented to provide insight over the entire lifespan of a request.For a list of libraries that can be instrumented, refer to theOpenTelemetry Registry.

Next Steps

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-05 UTC.