Skip to main content

A stub emulator for the Google Cloud Storage API

Project description

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)
  • cd into the repository directory
  • pip install -e
  • python -m unittest gcloud_storage_emulator.tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcloud-storage-emulator-0.4.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcloud_storage_emulator-0.4.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file gcloud-storage-emulator-0.4.1.tar.gz.

File metadata

  • Download URL: gcloud-storage-emulator-0.4.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11

File hashes

Hashes for gcloud-storage-emulator-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4e32952e9f2a4551b024bd097917eaf8f134ffc2c561e1a84018f6a97b0cc2b4
MD5 cfc17a7a51cd7225ef84878a2dac8437
BLAKE2b-256 b545e2a262b476b80376472306a048bbc062a39e6824b13662e2b51ab6fe8a5a

See more details on using hashes here.

File details

Details for the file gcloud_storage_emulator-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: gcloud_storage_emulator-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11

File hashes

Hashes for gcloud_storage_emulator-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68c524e7dfd27c5ef23997486b65c11d64eae2f3876d6a0beecfdbdebfbc2680
MD5 3f2967834cff2f29291b4ade922ceb4a
BLAKE2b-256 29b191fce53b0a218c4ab4db6583cfcddf59628a3d24998026cf9a22fc1674cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page