Metadata-Version: 2.4
Name: fastapi-storages
Version: 0.5.0
Summary: FastAPI Storages
Keywords: sqlalchemy,django,orm,fastapi
Author: Amin Alaee
Author-email: Amin Alaee <mohammadamin.alaee@gmail.com>
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Topic :: Database :: Database Engines/Servers
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Typing :: Typed
Requires-Dist: boto3~=1.25 ; extra == 'full'
Requires-Dist: pillow>=10 ; extra == 'full'
Requires-Dist: sqlalchemy>=1.4 ; extra == 'full'
Requires-Dist: peewee>=3 ; extra == 'full'
Requires-Dist: pillow>=10 ; extra == 'image'
Requires-Dist: peewee>=3 ; extra == 'peewee'
Requires-Dist: boto3~=1.25 ; extra == 's3'
Requires-Dist: sqlalchemy>=1.4 ; extra == 'sqlalchemy'
Requires-Python: >=3.10
Project-URL: Documentation, https://github.com/smithyhq/fastapi-storages#readme
Project-URL: Issues, https://github.com/smithyhq/fastapi-storages/issues
Project-URL: Source, https://github.com/smithyhq/fastapi-storages
Provides-Extra: full
Provides-Extra: image
Provides-Extra: peewee
Provides-Extra: s3
Provides-Extra: sqlalchemy
Description-Content-Type: text/markdown

<p align="center">
<a href="https://github.com/smithyhq/fastapi-storages">
    <img width="500px" src="https://raw.githubusercontent.com/smithyhq/fastapi-storages/main/docs/assets/images/banner.png" alt"FastAPI_Storages">
</a>
</p>

<p align="center">
<a href="https://github.com/smithyhq/fastapi-storages/actions">
    <img src="https://github.com/smithyhq/fastapi-storages/workflows/Tests/badge.svg" alt="Build Status">
</a>
<a href="https://github.com/smithyhq/fastapi-storages/actions">
    <img src="https://github.com/smithyhq/fastapi-storages/workflows/Publish/badge.svg" alt="Publish Status">
</a>
<a href="https://codecov.io/gh/smithyhq/fastapi-storages">
    <img src="https://codecov.io/gh/smithyhq/fastapi-storages/branch/main/graph/badge.svg" alt="Coverage">
</a>
<a href="https://pypi.org/project/fastapi-storages/">
    <img src="https://badge.fury.io/py/fastapi-storages.svg" alt="Package version">
</a>
<a href="https://pypi.org/project/fastapi-storages" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/fastapi-storages.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>

---

# FastAPI Storages

A collection of backend storages and ORM extensions to simplify file management in FastAPI and Starlette projects.

Similar to `django-storages` project, but aiming to work with a wider range of database ORMs and backends.

---

**Documentation**: [https://smithyhq.github.io/fastapi-storages](https://smithyhq.github.io/fastapi-storages)

**Source Code**: [https://github.com/smithyhq/fastapi-storages](https://github.com/smithyhq/fastapi-storages)

---

## Installation

```console
pip install fastapi-storages
```

Install optional extras based on what you need:

```console
pip install 'fastapi-storages[s3]'
pip install 'fastapi-storages[sqlalchemy]'
pip install 'fastapi-storages[peewee]'
pip install 'fastapi-storages[image]'
pip install 'fastapi-storages[full]'
```

## Supported integrations

- `SQLAlchemy`
- `SQLModel`
- `SQLAdmin`

## Supported storage backends

- `FileSystemStorage`
- `S3Storage`

## Example

```python
from fastapi import FastAPI, UploadFile
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.orm import Session, declarative_base
from fastapi_storages import FileSystemStorage
from fastapi_storages.integrations.sqlalchemy import FileType

app = FastAPI()
Base = declarative_base()
engine = create_engine("sqlite:///test.db")


class Example(Base):
    __tablename__ = "example"

    id = Column(Integer, primary_key=True)
    file = Column(FileType(storage=FileSystemStorage(path="/tmp")))


# Create database and table
Base.metadata.create_all(engine)


@app.post("/upload/")
def create_upload_file(file: UploadFile):
    example = Example(file=file)
    with Session(engine) as session:
        session.add(example)
        session.commit()
        return {"filename": example.file.name}
```
