Skip to content
GitHubDiscord

Storage (lexigram-storage)

Unified blob storage abstraction for Lexigram Framework — S3, GCS, Azure Blob, and local filesystem


lexigram-storage provides a unified BlobStore interface over Amazon S3, Google Cloud Storage, Azure Blob Storage, Cloudflare R2, and local disk — with signed URLs, streaming uploads, content-type negotiation, and server-side encryption. All services are wired via StorageProvider, which registers the blob store protocol with the DI container.


Terminal window
uv add lexigram-storage
# Optional extras
uv add "lexigram-storage[s3]" # Amazon S3 (aiobotocore)
uv add "lexigram-storage[gcp]" # Google Cloud Storage
uv add "lexigram-storage[azure]" # Azure Blob Storage
from lexigram import Application
from lexigram.di.module import Module, module
# Import the module from the package
from lexigram.storage import StorageModule
@module(imports=[StorageModule.configure(...)])
class AppModule(Module):
pass
app = Application(modules=[AppModule])
if __name__ == "__main__":
app.run()

Zero-config usage: Call StorageModule.configure() with no arguments to use defaults.

application.yaml
storage:
default_driver: "s3"
drivers:
s3:
bucket: "my-app-uploads"
region: "us-east-1"
access_key: "${AWS_ACCESS_KEY_ID}"
secret_key: "${AWS_SECRET_ACCESS_KEY}"
Section titled “Option 2 — Profiles + Environment Variables (recommended)”
Terminal window
export LEX_STORAGE__ENABLED=true
# Environment variables for each field
from lexigram.storage.config import StorageConfig
from lexigram.storage import StorageModule
config = StorageConfig(default_driver="s3", ...)
StorageModule.configure(config)
FieldDefaultEnv varDescription
default_driver"local"LEX_STORAGE__DEFAULT_DRIVERActive driver: s3, gcs, azure, r2, local, memory
drivers.s3.bucketLEX_STORAGE__DRIVERS__S3__BUCKETS3 bucket name
drivers.s3.region"us-east-1"LEX_STORAGE__DRIVERS__S3__REGIONAWS region
drivers.s3.access_keyLEX_STORAGE__DRIVERS__S3__ACCESS_KEYAWS access key ID
drivers.s3.secret_keyLEX_STORAGE__DRIVERS__S3__SECRET_KEYAWS secret access key
drivers.s3.endpoint_urlnullLEX_STORAGE__DRIVERS__S3__ENDPOINT_URLOverride endpoint (MinIO, LocalStack)
drivers.gcs.bucketLEX_STORAGE__DRIVERS__GCS__BUCKETGCS bucket name
drivers.gcs.credentials_pathLEX_STORAGE__DRIVERS__GCS__CREDENTIALS_PATHPath to service account JSON
drivers.azure.account_nameLEX_STORAGE__DRIVERS__AZURE__ACCOUNT_NAMEAzure storage account name
drivers.azure.containerLEX_STORAGE__DRIVERS__AZURE__CONTAINERAzure blob container
drivers.local.root_dirLEX_STORAGE__DRIVERS__LOCAL__ROOT_DIRRoot directory for local storage
service.max_file_size_mb100LEX_STORAGE__SERVICE__MAX_FILE_SIZE_MBMaximum upload size in MB
MethodDescription
StorageModule.configure(config, enable_encryption)Configure with explicit StorageConfig
StorageModule.stub()Minimal config for testing
  • S3 — Multi-part upload, server-side encryption, lifecycle rules
  • GCS — Resumable uploads, CMEK, uniform bucket-level access
  • Azure — Block blobs, shared access signatures (SAS), CDN integration
  • R2 — Cloudflare R2 (S3-compatible) support
  • Local driver — On-disk storage for development and CI
  • Memory driver — In-process storage for unit tests
  • Signed URLs — Time-limited GET / PUT pre-signed URLs for direct browser upload
  • Content negotiation — Automatic MIME type detection from extension and magic bytes
  • Key-value store — Lightweight KVStore for small blobs (config, flags)
  • Streamingput_stream() / get_stream() for arbitrarily large files
async with Application.boot(modules=[StorageModule.stub()]) as app:
# your test code
...
FileWhat it contains
src/lexigram/storage/module.pyStorageModule class with factory methods
src/lexigram/storage/di/provider.pyStorageProvider — wires storage protocols into DI container
src/lexigram/storage/config.pyStorageConfig and sub-config classes
src/lexigram/storage/drivers/Driver implementations (S3, GCS, Azure, R2, local, memory)
src/lexigram/storage/blob.pyBlobStore interface implementation