Blobby provides uniform interface for object storage solutions of common cloud providers. It also provides a local filesystem-based implementation and an in-memory implementation for local development and testing.
In addition to the core APIs for manipulating and retrieving binary data, blobby also provides convenient wrappers to write and read pydantic objects serialised as JSON documents.
Provider support
- AWS S3
- Azure Blob Storage
- Filesystem
- Google Cloud Storage
- In-memory
Creating a storage
All storage implementations inherit from blobby.Storage and
offer a uniform API.
AWS S3 storage
:warning: Install blobby with the
awsextra, i.e.pip install blobby[aws]
The S3 implementation uses a boto3 client, which needs to be
passed in when the storage is initialised. An S3 storage object
represents a bucket, whose name also needs to be supplied.
import boto3
from blobby.aws import S3Storage
client = boto3.client("s3")
storage = S3Storage(client=client, bucket_name="my-bucket")
Azure Blob Storage
:warning: Install blobby with the
azureextra, i.e.pip install blobby[azure]
The Azure implementation leverages the Azure SDK for Python. The storage expects the storage client to be provided.
from azure.storage.blob import BlobServiceClient
from blobby.azure import AzureBlobStorage
url = "<connection_string>"
service_client = BlobServiceClient.from_connection_string(url)
container_client = service_client.create_container("my-container")
storage = AzureBlobStorage(container_client)
Google Cloud Storage
:warning: Install blobby with the
gcpextra, i.e.pip install blobby[gcp]
The Google Cloud Storage leverages the official SDK for Cloud Storage. The bucket object needs to be supplied to the storage when it's initialised.
from google.cloud.storage import Client
from blobby.gcp import GoogleCloudStorage
client = Client()
bucket = client.bucket("my-bucket")
storage = GoogleCloudStorage(bucket)
Filesystem storage
When creating a filesystem-based storage, the root directory needs to be provided. All files will be relative to this directory.
from blobby.filesystem import FileSystemStorage
storage = FileSystemStorage(root_dir="/my/storage/", create_missing_dirs=True)
The create_missing_dirs flag controls whether the root directory
will be automatically created if it doesn't already exist.
In-memory storage
The in-memory implementation is backed with a simple dictionary stored in memory.
from blobby.memory import MemoryStorage
storage = MemoryStorage()
Common operations
Putting objects
The put operation works with bytes and str inputs.
In either case, the object is stored as a binary blob.
key = "my-object"
data = b"hello world"
storage.put(key, data)
In the case of filesystem storage, the key needs to be a valid path.
Getting objects
key = "my-object"
storage.get(key)
Deleting objects
key = "my-object"
storage.delete(key)
Listing objects
Currently, only listing by object prefix is supported. This isn't very natural for filesystems, but the primary focus of this library is object storage solutions, which often don't have the concept of a folder or directory.
prefix = "my/prefix"
storage.list(prefix)
Pydantic objects
Pydantic objects can be written and read using dedicated APIs for convenience.
class MyData(pydantic.BaseModel):
foo: str
bar: int
key = "my/data"
data = MyData(foo="hello", bar=1)
storage.put_model_object(key, data)
Error handling
Storage implementations map their internal errors
to shared error types, which are contained in blobby.error.
from blobby.error import NoSuchKeyError
try:
storage.get("test")
except NoSuchKeyError as err:
# do something with err
pass
Metadata
Release files for blobby 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| blobby-0.2.1.tar.gz | 7.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| blobby-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.5 kB
Release files / blobby-0.2.1.tar.gz
| Download URL | blobby-0.2.1.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15ad4a0a8330501ff58183e49f4f5a38c24723a701922c351be55092f40be708
|
|
BLAKE2b-256 checksum How to use checksums |
a3e283fac0acdbf9318a7e27f811f98b052d329c1b73128dde7b341d2b3b1673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.4
|
Release files / blobby-0.2.1-py3-none-any.whl
| Download URL | blobby-0.2.1-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ccf2eb7022cfdcd7aea980ae726cc65bd278bcf4a65c05947e37e090ba31817
|
|
BLAKE2b-256 checksum How to use checksums |
b161c64f8b6a6fd1ea3e88096264806c0b8b4466a3cde5190f607d8a5fa0534d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.4
|
Security for blobby 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.