The `gcp-storage-emulator` is a Python library that provides a stub emulator for the Google Cloud Storage API, enabling local development and testing without requiring a connection to the actual Google Cloud Storage service. It's actively maintained, with frequent releases, and is currently at version 2024.8.3. This emulator is particularly useful for accelerating development cycles and running integration tests locally.
pip install gcp-storage-emulatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically start the `gcp-storage-emulator`, configure the `google-cloud-storage` client to interact with it, and perform basic operations like creating a bucket, uploading a blob, and downloading its content. The emulator is configured for in-memory storage for ephemeral testing.
Consult the project's GitHub README and open issues for supported features. For critical missing features, consider contributing or using a more comprehensive solution like MinIO configured for GCS interoperability if S3 API compatibility is acceptable.
Ensure the `STORAGE_EMULATOR_HOST` environment variable points to a resolvable IP or hostname (e.g., `http://localhost:9023` or `http://host.docker.internal:9023` if using Docker Compose) that the client can reach. Check GitHub issues for specific workarounds related to `0.0.0.0` hostnames in callback URLs.
For ephemeral testing, use the `--in-memory` CLI flag or `in_memory=True` when calling `create_server()`. For controlled persistence, specify `STORAGE_BASE` and `STORAGE_DIR` environment variables or use the `gcp-storage-emulator wipe` command.
Always set `STORAGE_EMULATOR_HOST` to the emulator's address (e.g., `http://localhost:9023`) before initializing `google.cloud.storage.Client`. Use `os.environ.setdefault()` for flexible configuration.