Local Emulator for Google Cloud Storage
Google doesn't (yet) ship an emulator for the Cloud Storage API like they do for Cloud Datastore.
This is a stub emulator so you can run your tests and do local development without having to connect to the production Storage APIs.
THIS IS A WORK IN PROGRESS AND ONLY SUPPORTS A LIMITED SUBSET OF THE API
Looking for Commercial Support?
Potato offers Commercial Support for all its Open Source projects and we can tailor a support package to your needs.
If you're interested in commercial support, training, or consultancy then go ahead and contact us at opensource@potatolondon.com
Installation
pip install gcloud-storage-emulator
CLI Usage
Starting the emulator
Start the emulator with:
$ gcloud-storage-emulator start --port=9090
By default, data is stored under $PWD/.cloudstorage. You can configure the folder using the env variables STORAGE_BASE and STORAGE_DIR.
If you wish to run the emulator in a testing environment or if you don't want to persist any data, you can use the --no-store-on-disk parameter. For tests, you might want to consider starting up the server from your code (see the Python APIs)
If you're using the Google client library (e.g. google-cloud-storage for Python) then you can set the STORAGE_EMULATOR_HOST environment variable to tell the library to connect to your emulator endpoint rather than the standard https://storage.googleapis.com, e.g.:
$ export STORAGE_EMULATOR_HOST=http://localhost:9090
Wiping data
You can wipe the data by running
$ gcloud-storage-emulator wipe
You can pass --keep-buckets to wipe the data while keeping the buckets.
Python APIs
To start a server from your code you can do
from gcloud_storage_emulator.server import create_server
server = create_server("localhost", 9023, in_memory=False)
server.start()
# ........
server.stop()
You can wipe the data (e.g. for text execution) by calling server.wipe()
This can also be achieved (e.g. during tests) by hitting the /wipe endpoint
Running Tests
With Tox
If you have Tox installed then you can run tests with:
tox -e py37 -- {extra_pytest_args}
With Docker
If you don't have Tox installed on your system but you do have Docker, then you can run the tests using the themattrix/tox image:
docker run -v /ABSOLUTE/PATH/TO/THIS/REPO/ON/YOUR/MACHINE:/app themattrix/tox tox -e py37 [optional additional args for tox...]
With unittest
- Create and activate a virtualenv (optional but recommended)
cdinto the repository directorypip install -epython -m unittest gcloud_storage_emulator.tests
Release files for gcloud-storage-emulator 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gcloud-storage-emulator-0.5.0.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gcloud_storage_emulator-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.7 kB
Release files / gcloud-storage-emulator-0.5.0.tar.gz
| Download URL | gcloud-storage-emulator-0.5.0.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e56e111a962c3dafea1d9a446eb9ef13732bf72009696e9ebebdcb029a16b6df
|
|
BLAKE2b-256 checksum How to use checksums |
aeb78a1eebed452938e7554b746a3633f59cb09dee1b2f3074d13f92b8920fb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12
|
Release files / gcloud_storage_emulator-0.5.0-py3-none-any.whl
| Download URL | gcloud_storage_emulator-0.5.0-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69fe95ab57fc45acdeba7b8dfc44c12b9e7921e640776f7ec79d675d753b03cf
|
|
BLAKE2b-256 checksum How to use checksums |
f146b70e4ee5df71b4253c146c3792703c1e63c66c1e63d9bd64dbc07a1c456e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12
|