Storage Backends

This section documents all available storage backend implementations. Each backend implements the Storage protocol and provides a corresponding configuration dataclass.

Available Backends

Backend

Use Case

Dependencies

MemoryStorage

Testing, development

None (built-in)

FileSystemStorage

Local file storage

aiofiles

S3Storage

AWS S3, R2, Spaces, MinIO

aioboto3

GCSStorage

Google Cloud Storage

gcloud-aio-storage

AzureStorage

Azure Blob Storage

azure-storage-blob

Backend Modules

Choosing a Backend

For Testing and Development

Use MemoryStorage for unit tests and local development. Data is stored in memory and lost on restart.

from litestar_storages import MemoryStorage

storage = MemoryStorage()

For Local/Self-Hosted

Use FileSystemStorage when storing files on the local filesystem or network-attached storage.

from pathlib import Path
from litestar_storages import FileSystemStorage, FileSystemConfig

storage = FileSystemStorage(
    config=FileSystemConfig(
        path=Path("/var/uploads"),
        base_url="https://cdn.example.com/uploads",
    )
)

For AWS or S3-Compatible

Use S3Storage for Amazon S3 and S3-compatible services like Cloudflare R2, DigitalOcean Spaces, MinIO, etc.

from litestar_storages import S3Storage, S3Config

# AWS S3
storage = S3Storage(
    config=S3Config(
        bucket="my-bucket",
        region="us-east-1",
    )
)

# Cloudflare R2
storage = S3Storage(
    config=S3Config(
        bucket="my-bucket",
        endpoint_url="https://account.r2.cloudflarestorage.com",
        access_key_id="...",
        secret_access_key="...",
    )
)

For Google Cloud

Use GCSStorage for Google Cloud Storage.

from litestar_storages import GCSStorage, GCSConfig

storage = GCSStorage(
    config=GCSConfig(
        bucket="my-bucket",
        project="my-project",
    )
)

For Azure

Use AzureStorage for Azure Blob Storage.

from litestar_storages import AzureStorage, AzureConfig

storage = AzureStorage(
    config=AzureConfig(
        container="my-container",
        connection_string="DefaultEndpointsProtocol=https;...",
    )
)