FastAPI Storages
Project description
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
Source Code: https://github.com/aminalaee/fastapi-storages
Installation
pip install fastapi-storages
pip install 'fastapi-storages[full]'
Supported integrations
SQLAlchemy
SQLModel
SQLAdmin
Supported storage backends
FileSystemStorage
S3Storage
Example
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}
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_storages-0.1.0.tar.gz
(5.9 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_storages-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd7c6bdbe4ae03969588adfb7b19162a93703addb1aebf803dfc68576ede2a8 |
|
MD5 | e331713b72d264affd71d274d658e171 |
|
BLAKE2b-256 | 1e82335d1f861a5b59919f47dc13817f026a7c968fbd297d942d8c94b27190f6 |