<p align="center">
<a href="https://github.com/aminalaee/fastapi-storages">
<img width="500px" src="https://raw.githubusercontent.com/aminalaee/fastapi-storages/main/docs/assets/images/banner.png" alt"FastAPI_Storages">
</a>
</p>
<p align="center">
<a href="https://github.com/aminalaee/fastapi-storages/actions">
<img src="https://github.com/aminalaee/fastapi-storages/workflows/Tests/badge.svg" alt="Build Status">
</a>
<a href="https://github.com/aminalaee/fastapi-storages/actions">
<img src="https://github.com/aminalaee/fastapi-storages/workflows/Publish/badge.svg" alt="Publish Status">
</a>
<a href="https://codecov.io/gh/aminalaee/fastapi-storages">
<img src="https://codecov.io/gh/aminalaee/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://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 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}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-storages",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "django,fastapi,orm,sqlalchemy",
"author": null,
"author_email": "Amin Alaee <me@aminalaee.dev>",
"download_url": "https://files.pythonhosted.org/packages/9d/3f/5866860d87293ef09fe908e4a7c871e2597d24934a3e9d20bd7e942f162a/fastapi_storages-0.2.1.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n<a href=\"https://github.com/aminalaee/fastapi-storages\">\n <img width=\"500px\" src=\"https://raw.githubusercontent.com/aminalaee/fastapi-storages/main/docs/assets/images/banner.png\" alt\"FastAPI_Storages\">\n</a>\n</p>\n\n<p align=\"center\">\n<a href=\"https://github.com/aminalaee/fastapi-storages/actions\">\n <img src=\"https://github.com/aminalaee/fastapi-storages/workflows/Tests/badge.svg\" alt=\"Build Status\">\n</a>\n<a href=\"https://github.com/aminalaee/fastapi-storages/actions\">\n <img src=\"https://github.com/aminalaee/fastapi-storages/workflows/Publish/badge.svg\" alt=\"Publish Status\">\n</a>\n<a href=\"https://codecov.io/gh/aminalaee/fastapi-storages\">\n <img src=\"https://codecov.io/gh/aminalaee/fastapi-storages/branch/main/graph/badge.svg\" alt=\"Coverage\">\n</a>\n<a href=\"https://pypi.org/project/fastapi-storages/\">\n <img src=\"https://badge.fury.io/py/fastapi-storages.svg\" alt=\"Package version\">\n</a>\n<a href=\"https://pypi.org/project/fastapi-storages\" target=\"_blank\">\n <img src=\"https://img.shields.io/pypi/pyversions/fastapi-storages.svg?color=%2334D058\" alt=\"Supported Python versions\">\n</a>\n</p>\n\n---\n\n# FastAPI Storages\n\nA collection of backend storages and ORM extensions to simplify file management in FastAPI and Starlette projects.\n\nSimilar to `django-storages` project, but aiming to work with a wider range of database ORMs and backends.\n\n---\n\n**Documentation**: [https://aminalaee.dev/fastapi-storages](https://aminalaee.dev/fastapi-storages)\n\n**Source Code**: [https://github.com/aminalaee/fastapi-storages](https://github.com/aminalaee/fastapi-storages)\n\n---\n\n## Installation\n\n```console\npip install fastapi-storages\npip install 'fastapi-storages[full]'\n```\n\n## Supported integrations\n\n- `SQLAlchemy`\n- `SQLModel`\n- `SQLAdmin`\n\n## Supported storage backends\n\n- `FileSystemStorage`\n- `S3Storage`\n\n## Example\n\n```python\nfrom fastapi import FastAPI, UploadFile\nfrom sqlalchemy import Column, Integer, create_engine\nfrom sqlalchemy.orm import Session, declarative_base\nfrom fastapi_storages import FileSystemStorage\nfrom fastapi_storages.integrations.sqlalchemy import FileType\n\napp = FastAPI()\nBase = declarative_base()\nengine = create_engine(\"sqlite:///test.db\")\n\n\nclass Example(Base):\n __tablename__ = \"example\"\n\n id = Column(Integer, primary_key=True)\n file = Column(FileType(storage=FileSystemStorage(path=\"/tmp\")))\n\n\n# Create database and table\nBase.metadata.create_all(engine)\n\n\n@app.post(\"/upload/\")\ndef create_upload_file(file: UploadFile):\n example = Example(file=file)\n with Session(engine) as session:\n session.add(example)\n session.commit()\n return {\"filename\": example.file.name}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "FastAPI Storages",
"version": "0.2.1",
"project_urls": {
"Documentation": "https://github.com/aminalaee/fastapi-storages#readme",
"Issues": "https://github.com/aminalaee/fastapi-storages/issues",
"Source": "https://github.com/aminalaee/fastapi-storages"
},
"split_keywords": [
"django",
"fastapi",
"orm",
"sqlalchemy"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ec6743a5a0ab66dc688438df903655f4d8ef575bffef39438a8fd5966b3c8134",
"md5": "9309610cb535ad71a15d3dcdd323b72a",
"sha256": "e0382c972a70a9b286af5fe26f3a165587b0f898f5588aac95f616b05a1342a0"
},
"downloads": -1,
"filename": "fastapi_storages-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9309610cb535ad71a15d3dcdd323b72a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8637,
"upload_time": "2023-12-14T11:14:02",
"upload_time_iso_8601": "2023-12-14T11:14:02.788189Z",
"url": "https://files.pythonhosted.org/packages/ec/67/43a5a0ab66dc688438df903655f4d8ef575bffef39438a8fd5966b3c8134/fastapi_storages-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9d3f5866860d87293ef09fe908e4a7c871e2597d24934a3e9d20bd7e942f162a",
"md5": "364b4290bd3c9d3b2a8a452c5b328aa8",
"sha256": "f0ecbd7106c58b16b0b78dc83dfb98f0b4d348760bae385a674ec0bcb6d1a9b4"
},
"downloads": -1,
"filename": "fastapi_storages-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "364b4290bd3c9d3b2a8a452c5b328aa8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6474,
"upload_time": "2023-12-14T11:14:04",
"upload_time_iso_8601": "2023-12-14T11:14:04.416321Z",
"url": "https://files.pythonhosted.org/packages/9d/3f/5866860d87293ef09fe908e4a7c871e2597d24934a3e9d20bd7e942f162a/fastapi_storages-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-14 11:14:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aminalaee",
"github_project": "fastapi-storages#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fastapi-storages"
}