gsutil is a Python application that serves as a command-line tool for interacting with Google Cloud Storage. It allows users to perform a wide range of bucket and object management tasks, such as creating and deleting buckets, uploading, downloading, and deleting objects, and managing ACLs. While `gsutil` is functional and widely documented, Google now recommends using `gcloud storage` commands from the Google Cloud CLI for Cloud Storage interactions due to better performance and support for newer features. The current version is 5.36, and it sees regular maintenance releases.
pip install gsutilNo compatibility data collected yet for this library.
This quickstart demonstrates how to interact with `gsutil` from Python by calling it as a subprocess. This is the common pattern for programmatic use, as `gsutil` is primarily a command-line interface. It includes creating a bucket, uploading a file, listing contents, downloading a file, and cleaning up resources.
Transition scripts and workflows to use `gcloud storage` commands. Refer to the 'Transition from gsutil to gcloud storage' documentation.
For direct integration into Python applications, use the `google-cloud-storage` client library (e.g., `pip install google-cloud-storage`). If `gsutil` CLI functionality is strictly required, use Python's `subprocess` module to execute `gsutil` commands.
Ensure your environment uses a compatible Python version (3.9-3.13 for recent `gsutil` versions). Upgrade Python if necessary.
Thoroughly review and update any automated scripts that rely on parsing `gsutil` output if migrating to `gcloud storage`.
For optimal performance with large transfers, especially for new projects, consider using `gcloud storage`. If sticking with `gsutil`, explore options like the `-m` (multi-threaded/multi-processing) flag for `cp` and `rsync` operations, or adjusting `parallel_process_count` and `parallel_thread_count` settings in the `.boto` configuration.
Install the `crcmod` C extension by running `pip install -U crcmod`. Ensure that development tools (like `gcc` and Python headers) are installed on your system if you encounter compilation issues.
Install the Google Cloud SDK and ensure that its `bin` directory (e.g., `/path/to/google-cloud-sdk/bin`) is added to your system's PATH. Alternatively, execute `gsutil` by specifying its full path.
Grant the appropriate IAM role (e.g., `Storage Object Viewer`, `Storage Object Creator`, `Storage Admin`, or a custom role with specific permissions) to the principal on the bucket or object via the Google Cloud Console or `gcloud iam` commands.
Run `gcloud auth login` in your terminal to authenticate with your Google Cloud account through a web browser. If using a service account, activate it with `gcloud auth activate-service-account --key-file=/path/to/key.json`.
Grant the required IAM roles (e.g., `roles/storage.objectViewer`, `roles/storage.objectCreator`, `roles/storage.objectAdmin`, `roles/storage.bucketAdmin`) to the principal associated with your `gcloud` credentials in the Google Cloud Console for the relevant project and resource.