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
Built Distribution
File details
Details for the file fastapi_storages-0.3.0.tar.gz
.
File metadata
- Download URL: fastapi_storages-0.3.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f784335fff9cd163b783e842da04c6d9ed1b306fce8995fda109b170d6d453df |
|
MD5 | 951f5f2bc5fdaf2c350e9b2cd1139dd0 |
|
BLAKE2b-256 | 688ae56d4ade659994c2989091b96642f10554ec3914a40de56a556ffdbbcd26 |
File details
Details for the file fastapi_storages-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: fastapi_storages-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91adb41a80fdef2a84c0f8244c27ade7ff8bd5db9b7fa95c496c06c03e192477 |
|
MD5 | 2cff8866c040327fbb02969e25d296e2 |
|
BLAKE2b-256 | a7b53fb94b4f329fb2f83ffa54e6941b769deaaaa77f63a9fe70905219dd7339 |