The `google-cloud-storage-control` library provides a Python client for interacting with the Google Cloud Storage Control API. This API allows for programmatic management of Storage features like Managed Folders and other bucket-level controls. It is currently at version 1.11.0 and is part of the larger `google-cloud-python` monorepo, receiving frequent updates along with other Google Cloud client libraries.
pip install google-cloud-storage-controlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `StorageControlClient` and list managed folders within a specified Google Cloud Storage bucket. Ensure your `GOOGLE_CLOUD_PROJECT` and `GCS_BUCKET_NAME` environment variables are set, and your environment is authenticated (e.g., via `gcloud auth application-default login`).
Upgrade to `google-cloud-storage-control>=1.0.0` and consult the official changelog for specific migration steps. Re-evaluate client instantiation and method calls to align with the `v2` API.
Ensure the service account or user making the request has the necessary Storage Control permissions, such as `roles/storage.admin` or custom roles with granular permissions for `managedFolders.create`, `managedFolders.get`, `managedFolders.list`, `managedFolders.delete`.
Always construct resource paths using the exact `projects/{project_id}/buckets/{bucket_name}` pattern, or other specific resource patterns as documented for each method, to avoid `Invalid argument` errors.Upgrade your Python environment to version 3.10 or newer. After upgrading Python, ensure that `google-api-core`, `google-auth`, and `google-cloud-storage-control` are updated to their latest versions.
Ensure the `GOOGLE_CLOUD_PROJECT` environment variable is set or explicitly pass your project ID when initializing the client or making API calls that require it, for example: `ManagedFolderClient(project='your-gcp-project-id')`.
Ensure the library is correctly installed using pip: `pip install google-cloud-storage-control`
The `StorageControlClient` should be imported from `google.cloud.storage_control_v2.services.storage_control.client` (or similar versioned path) or just `google.cloud.storage_control_v2` and then instantiated. The recommended way is to import the main client from the root of the installed library `google.cloud.storage_control_v2` and then access the client directly. For `google-cloud-storage-control` (which is `storage_control_v2` under the hood), the current recommended import is: `from google.cloud import storage_control_v2 client = storage_control_v2.StorageControlClient()`
Grant the appropriate IAM roles to the principal. For Managed Folders, this typically includes roles like `Storage Managed Folder Creator`, `Storage Managed Folder Viewer`, `Storage Managed Folder Deleter`, or custom roles with permissions like `storage.managedFolders.create` or `storage.managedFolders.update` at the project or bucket level.
Ensure the Managed Folder name ends with a forward slash (`/`) and complies with all other naming rules (e.g., valid Unicode characters, no control characters, no `.` or `..`, max 15 slashes for nesting depth). For example: `managed_folder_name = 'my-managed-folder/'`