- 3.5.0 (latest)
- 3.4.1
- 3.3.1
- 3.2.0
- 3.1.1
- 3.0.0
- 2.19.0
- 2.17.0
- 2.16.0
- 2.15.0
- 2.14.0
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.1
- 2.1.0
- 2.0.0
- 1.44.0
- 1.43.0
- 1.42.3
- 1.41.1
- 1.40.0
- 1.39.0
- 1.38.0
- 1.37.1
- 1.36.2
- 1.35.1
- 1.34.0
- 1.33.0
- 1.32.0
- 1.31.2
- 1.30.0
- 1.29.0
- 1.28.1
- 1.27.0
- 1.26.0
- 1.25.0
- 1.24.1
- 1.23.0
- 1.22.0
- 1.21.0
- 1.20.0
- 1.19.0
- 1.18.0
- 1.17.0
Python Client for Google Cloud Storage
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.
3.0 Major Version Notes
Feedback Welcome
If you experience that backwards compatibility for your application is brokenwith this major version release, please let us know through the Github issuessystem. While some breaks of backwards compatibility may be unavoidable due tonew features in the major version release, we will do our best to minimizethem. Thank you.
Exception Handling
In Python Storage 3.0, the dependencygoogle-resumable-media was integrated.Thegoogle-resumable-media dependency included exceptionsgoogle.resumable_media.common.InvalidResponse andgoogle.resumable_media.common.DataCorruption, which were often importeddirectly in user application code. The replacements for these exceptions aregoogle.cloud.storage.exceptions.InvalidResponse andgoogle.cloud.storage.exceptions.DataCorruption. Please update application codeto import and use these exceptions instead.
For backwards compatibility, ifgoogle-resumable-media is installed, the newexceptions will be defined as subclasses of the old exceptions, so applicationsshould continue to work without modification. This backwards compatibilityfeature may be removed in a future major version update.
Some users may be using the original exception classes from thegoogle-resumable-media library without explicitly installing that library. Soas not to break user applications following this pattern,google-resumable-media is still in the list of dependencies in this package’ssetup.py file. Applications which do not import directly fromgoogle-resumable-media can safely disregard this dependency.This backwards compatibility featurewill be removed in a future majorversion update. Please migrate to using thegoogle.cloud.storage.exceptionsclasses as above.
Checksum Defaults
In Python Storage 3.0, uploads and downloads now have a default of “auto” whereapplicable. “Auto” will use crc32c checksums, except for unusual cases where thefast (C extension) crc32c implementation is not available, in which case it willuse md5 instead. Before Python Storage 3.0, the default was md5 for mostdownloads and None for most uploads. Note that ranged downloads (“start” or“end” set) still do not support any checksumming, and some features intransfer_manager.py still support crc32c only.
Note: The methodBlob.upload_from_file() requires a file in bytes mode, butwhen checksum is set to None, as was the previous default, would not throw anerror if passed a file in string mode under some circumstances. With the newdefaults, it will now raise a TypeError. Please use a file opened in bytesreading mode as required.
Miscellaneous
The
BlobWriterclass now attempts to terminate an ongoing resumable upload ifthe writer exits with an exception.Retry behavior is now identical between media operations (uploads anddownloads) and other operations, and custom predicates are now supported formedia operations as well.
Blob.download_as_filename()will now delete the empty file if it results in agoogle.cloud.exceptions.NotFound exception (HTTP 404).Previously, object upload, metadata update, and delete methods had retriesdisabled by default unless the generation or metageneration was specified inthe request. This has now changed so that retries are enabled by default.
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.
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-storageWindows
py -m venv <your-env>.\<your-env>\Scripts\activatepip install google-cloud-storageTracing 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=TrueYou 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-requestsfrom 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
Read theGoogle Cloud Storage Product documentation to learnmore about the product and see How-to Guides.
Read theClient Library Documentation for Google Cloud Storage APIto see other available methods on the client.
View thisREADME to see the full list of CloudAPIs that we cover.
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.