Minimal async key-value store backed by local or cloud blob storage
Project description
asyncblobdict
asyncblobdict is a minimal async‑friendly key–value store for JSON and binary data, backed by either:
- Local filesystem
- Azure Blob Storage
It lets you store and retrieve Python data by key, with optional caching and optimistic concurrency via ETags. Swap backends without changing your application code.
Features
- Backends: Local filesystem or Azure Blob Storage
- Data types:
- JSON‑serializable (
dict,list,set,datetime, etc.) - Arbitrary binary (
bytes,bytearray)
- JSON‑serializable (
- Caching modes:
NONE- always read/write directly to backendWRITE_THROUGH- cache and immediately write to backendWRITE_BACK- cache and sync later
- Concurrency modes:
NONE- no concurrency controlETAG- optimistic concurrency using ETags
Installation
From PyPI:
pip install asyncblobdict
For development (editable install):
git clone https://github.com/ViLahte/asyncblobdict.git
cd asyncblobdict
pip install -e .
Quick Start
Local backend example
import asyncio
import pickle
from datetime import datetime
from asyncblobdict import AsyncBlobStore, CacheMode, ConcurrencyMode, LocalFileAdapter, BlobNotFoundError
async def main():
adapter = LocalFileAdapter("./local_blob_storage")
async with AsyncBlobStore(
adapter,
"demo_container",
cache_mode=CacheMode.WRITE_THROUGH,
concurrency_mode=ConcurrencyMode.ETAG,
) as store:
# Store JSON
config = {"learning_rate": 0.01, "layers": [64, 128, 256], "created_at": datetime.utcnow()}
await store.set_json("demo/config", config)
# Retrieve JSON
loaded_config = await store.get_json("demo/config")
print("Loaded config:", loaded_config)
# Store binary
model_bytes = pickle.dumps({"weights": [0.1, 0.2, 0.3], "bias": 0.5})
await store.set_binary("demo/model.bin", model_bytes)
# Retrieve binary
loaded_model = pickle.loads(await store.get_binary("demo/model.bin"))
print("Loaded model:", loaded_model)
# List keys
print("Keys:", await store.list_keys())
# Delete a key
await store.delete("demo/config")
try:
await store.get_json("demo/config")
except BlobNotFoundError:
print("Config deleted successfully.")
if __name__ == "__main__":
asyncio.run(main())
Azure backend example
Requires environment variables:
AZURE_CONN_STR=your-azure-connection-string
AZURE_CONTAINER=your-container-name
import os
import asyncio
from datetime import datetime
from dotenv import load_dotenv
from asyncblobdict import AsyncBlobStore, CacheMode, ConcurrencyMode, AzureBlobAdapter
load_dotenv()
async def main():
adapter = AzureBlobAdapter.from_connection_string(os.environ["AZURE_CONN_STR"])
async with AsyncBlobStore(
adapter,
os.environ["AZURE_CONTAINER"],
cache_mode=CacheMode.WRITE_THROUGH,
concurrency_mode=ConcurrencyMode.ETAG,
) as store:
await store.set_json("demo/config", {"created_at": datetime.utcnow()})
print(await store.get_json("demo/config"))
if __name__ == "__main__":
asyncio.run(main())
Syncing in WRITE_BACK mode
When using CacheMode.WRITE_BACK, changes are cached locally until you call:
await store.sync(etag_behavior="skip") # options: "skip", "overwrite", "raise"
Testing
We use pytest:
pytest
Azure tests are skipped automatically if environment variables are not set. You can also run only local tests:
pytest -m "not azure"
Or only Azure tests:
pytest -m azure
For code coverage html report:
pytest --cov=src --cov-report=html
License
MIT License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncblobdict-0.1.13.tar.gz.
File metadata
- Download URL: asyncblobdict-0.1.13.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2c73bbc4e8d34fad9ae1237cabb88da2e55fa4949bf00f5d28ea3c71eec35fc
|
|
| MD5 |
c03fd79a906c2eb0d368a1b5a440a0a1
|
|
| BLAKE2b-256 |
d47462ecdbb9dc70d9b6f6e2c08387c03f2a107cdc5e9d539228ecff41d72c86
|
File details
Details for the file asyncblobdict-0.1.13-py3-none-any.whl.
File metadata
- Download URL: asyncblobdict-0.1.13-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35d4fa44acfad2c03534766ac504373cc5479641b6924dc3c9d135c6503eac3c
|
|
| MD5 |
b6bc3ebca420258a9c48dbe6263a5cb8
|
|
| BLAKE2b-256 |
3975793e16112debc1c33ecd0341cc8567cc083f6c6c5a08007710fd214b2747
|