Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aminalaee/fastapi-storages
FastAPI backend storages and ORM extensions
https://github.com/aminalaee/fastapi-storages
fastapi orm python sqlalchemy starlette
Last synced: 6 days ago
JSON representation
FastAPI backend storages and ORM extensions
- Host: GitHub
- URL: https://github.com/aminalaee/fastapi-storages
- Owner: aminalaee
- License: mit
- Created: 2023-01-26T09:45:34.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-06T07:55:51.000Z (4 months ago)
- Last Synced: 2024-12-14T02:09:17.020Z (13 days ago)
- Topics: fastapi, orm, python, sqlalchemy, starlette
- Language: Python
- Homepage: https://aminalaee.dev/fastapi-storages
- Size: 671 KB
- Stars: 66
- Watchers: 6
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
---
# 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://aminalaee.dev/fastapi-storages](https://aminalaee.dev/fastapi-storages)
**Source Code**: [https://github.com/aminalaee/fastapi-storages](https://github.com/aminalaee/fastapi-storages)
---
## Installation
```console
pip install fastapi-storages
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 FileTypeapp = 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}
```