All Projects → oittaa → gcp-storage-emulator

oittaa / gcp-storage-emulator

Licence: BSD-3-Clause license
Local emulator for Google Cloud Storage

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to gcp-storage-emulator

Csi Gcs
Kubernetes CSI driver for Google Cloud Storage
Stars: ✭ 44 (+2.33%)
Mutual labels:  storage, google-cloud-storage, gcp
Fake Gcs Server
Google Cloud Storage emulator & testing library.
Stars: ✭ 316 (+634.88%)
Mutual labels:  emulator, storage, gcp
Flydrive
☁️ Flexible and Fluent framework-agnostic driver based system to manage storage in Node.js
Stars: ✭ 275 (+539.53%)
Mutual labels:  storage, google-cloud-storage
Fog Google
Fog for Google Cloud Platform
Stars: ✭ 83 (+93.02%)
Mutual labels:  storage, gcp
Mc
MinIO Client is a replacement for ls, cp, mkdir, diff and rsync commands for filesystems and object storage.
Stars: ✭ 1,962 (+4462.79%)
Mutual labels:  storage, google-cloud-storage
storage
Go library providing common interface for working across multiple cloud storage backends
Stars: ✭ 154 (+258.14%)
Mutual labels:  storage, gcs
arc gcs
Provides an Arc backend for Google Cloud Storage
Stars: ✭ 48 (+11.63%)
Mutual labels:  storage, google-cloud-storage
Thanos
Highly available Prometheus setup with long term storage capabilities. A CNCF Incubating project.
Stars: ✭ 9,820 (+22737.21%)
Mutual labels:  storage, google-cloud-storage
Clocal Gcp
🔭 Emulation engine for GCP
Stars: ✭ 63 (+46.51%)
Mutual labels:  emulator, gcp
fluent-plugin-gcs
Google Cloud Storage output plugin for Fluentd.
Stars: ✭ 39 (-9.3%)
Mutual labels:  gcp, gcs
Goofys
a high-performance, POSIX-ish Amazon S3 file system written in Go
Stars: ✭ 3,932 (+9044.19%)
Mutual labels:  google-cloud-storage, gcs
go-storage
A vendor-neutral storage library for Golang: Write once, run on every storage service.
Stars: ✭ 387 (+800%)
Mutual labels:  storage, gcs
spring-cloud-gcp-guestbook
No description or website provided.
Stars: ✭ 55 (+27.91%)
Mutual labels:  gcp, gcp-storage
benji
📁 This library is a Scala reactive DSL for object storage (e.g. S3/Amazon, S3/CEPH, Google Cloud Storage).
Stars: ✭ 18 (-58.14%)
Mutual labels:  storage, google-cloud-storage
Docker Android
Android in docker solution with noVNC supported and video recording
Stars: ✭ 4,042 (+9300%)
Mutual labels:  emulator, gcp
esop
Cloud-enabled backup and restore tool for Apache Cassandra
Stars: ✭ 40 (-6.98%)
Mutual labels:  storage, gcp
gcsfs
Google Cloud Storage filesystem for PyFilesystem2
Stars: ✭ 36 (-16.28%)
Mutual labels:  storage, gcs
rv32emu
RISC-V RV32I[MAC] emulator with ELF support
Stars: ✭ 61 (+41.86%)
Mutual labels:  emulator
switch-gba
Browser based Nintendo Switch GBA Emulator
Stars: ✭ 75 (+74.42%)
Mutual labels:  emulator
gce-cache-cluster
Easy groupcache clustering on GCE
Stars: ✭ 32 (-25.58%)
Mutual labels:  gcp

Local Emulator for Google Cloud Storage

CI PyPI codecov Code style: black

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


Installation

pip install gcp-storage-emulator

CLI Usage

Starting the emulator

Start the emulator with:

gcp-storage-emulator start

By default, the server will listen on http://localhost:9023 and data is stored under ./.cloudstorage. You can configure the folder using the env variables STORAGE_BASE (default ./) and STORAGE_DIR (default .cloudstorage).

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 --in-memory 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:9023

Wiping data

You can wipe the data by running

gcp-storage-emulator wipe

You can pass --keep-buckets to wipe the data while keeping the buckets.

Example

Use in-memory storage and automatically create default storage bucket my-bucket.

gcp-storage-emulator start --host=localhost --port=9023 --in-memory --default-bucket=my-bucket

Python APIs

To start a server from your code you can do

from gcp_storage_emulator.server import create_server

server = create_server("localhost", 9023, in_memory=False)

server.start()
# ........
server.stop()

You can wipe the data by calling server.wipe()

This can also be achieved (e.g. during tests) by hitting the /wipe HTTP endpoint

Example

import os

from google.cloud import storage
from gcp_storage_emulator.server import create_server

HOST = "localhost"
PORT = 9023
BUCKET = "test-bucket"

# default_bucket parameter creates the bucket automatically
server = create_server(HOST, PORT, in_memory=True, default_bucket=BUCKET)
server.start()

os.environ["STORAGE_EMULATOR_HOST"] = f"http://{HOST}:{PORT}"
client = storage.Client()

bucket = client.bucket(BUCKET)
blob = bucket.blob("blob1")
blob.upload_from_string("test1")
blob = bucket.blob("blob2")
blob.upload_from_string("test2")
for blob in bucket.list_blobs():
    content = blob.download_as_bytes()
    print(f"Blob [{blob.name}]: {content}")

server.stop()

Docker

Pull the Docker image.

docker pull oittaa/gcp-storage-emulator

Inside the container instance, the value of the PORT environment variable always reflects the port to which requests are sent. It defaults to 8080. The directory used for the emulated storage is located under /storage in the container. In the following example the host's directory $(pwd)/cloudstorage will be bound to the emulated storage.

docker run -d \
  -e PORT=9023 \
  -p 9023:9023 \
  --name gcp-storage-emulator \
  -v "$(pwd)/cloudstorage":/storage \
  oittaa/gcp-storage-emulator
import os

from google.cloud import exceptions, storage

HOST = "localhost"
PORT = 9023
BUCKET = "test-bucket"

os.environ["STORAGE_EMULATOR_HOST"] = f"http://{HOST}:{PORT}"
client = storage.Client()

try:
    bucket = client.create_bucket(BUCKET)
except exceptions.Conflict:
    bucket = client.bucket(BUCKET)

blob = bucket.blob("blob1")
blob.upload_from_string("test1")
print(blob.download_as_bytes())
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].