Skip to main content

A powerful, extensible, and async-ready cloud object storage backend for FastAPI.

Project description

fastapi-async-storages

GitHub branch check runs GitHub Actions Workflow Status Read the Docs Codecov PyPI - Version

A powerful, extensible, and async-ready cloud object storage backend for FastAPI.

Drop-in, plug-and-play cloud storage for your FastAPI apps; with full async support.
Inspired by fastapi-storages, built on modern async patterns using aioboto3.

Features

  • Fully asynchronous storage interface designed for FastAPI applications
  • Async S3 backend powered by aioboto3
  • SQLAlchemy and SQLModel integration
  • Typed and extensible design
  • Supports FastAPI dependency injection

Installation

uv add fastapi-async-storages
# for s3 support:
uv add "fastapi-async-storages[s3]"

Documentation

Full documentation is available on:
https://fastapi-async-storages.readthedocs.io

Example: FastAPI

from fastapi import FastAPI, UploadFile
from sqlalchemy import Column, Integer
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker, declarative_base
from async_storages import S3Storage
from async_storages.integrations.sqlalchemy import FileType

Base = declarative_base()

app = FastAPI()
storage = S3Storage(...)
engine = create_async_engine("sqlite+aiosqlite:///test.db", echo=True)

# create AsyncSession factory
AsyncSessionLocal = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

class Example(Base):
    __tablename__ = "example"

    id = Column(Integer, primary_key=True)
    file = Column(FileType(storage=storage))

# create tables inside an async context
@app.on_event("startup")
async def startup():
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

@app.post("/upload/")
async def create_upload_file(file: UploadFile):
    file_name = f"uploads/{file.filename}"
    # upload before commit due to the sqlalchemy binding being sync
    await storage.upload(file.file, file_name)

    example = Example(file=file)
    async with AsyncSessionLocal() as session:
        session.add(example)
        await session.commit()
        return {"filename": example.file.name}

License

MIT © 2025 ^_^ @stabldev

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

fastapi_async_storages-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_async_storages-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_async_storages-0.1.1.tar.gz.

File metadata

File hashes

Hashes for fastapi_async_storages-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b89b8ef801018306ed33bc457f08ea677485c3ef3a758ca5a57a1fd906e5fbae
MD5 e5c3a9373409a6697e433f5795338e0a
BLAKE2b-256 27c224fba160e00801555b45a5a6ee3062c9cdcb036c4f8f57d5ba658576b998

See more details on using hashes here.

File details

Details for the file fastapi_async_storages-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_async_storages-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa5007fa4b06e6dc20c1c8018d257cb95d092d882ff810c5084db4a65579f012
MD5 cdca3cd25b82f1f605ed67d39ac07236
BLAKE2b-256 9c28ed6ba548fb9e9e54ec031530e38b8627a2d317c82f5b33390bcadbff86b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page