FastAPI ORM Extensions
Project description
FastApi ORM Extensions
Table of Contents
About
This library provides preset base class for your tables and repositories.
Use TableBase like so:
from fastapi_orm_ext.table import TableBase
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Table(TableBase, DeclarativeBase):
# you can use this class in alembic's env.py file
# to specify target_metadata for example
__abstract__: bool = True
class User(Table, DeclarativeBase):
name: Mapped[str] = mapped_column(nullable=False)
surnname: Mapped[str | None] = mapped_column(nullable=True)
TableBase consists of four mixins:
- NameConventionMixin: handle name convention;
- TableNameMixin: takes model's class name and convert it to snake case, use this name while creating table in DB;
- TimestampsMixin: handles when record was created and updated;
- UUIDPrimaryKeyMixin: makes PK of UUID4 type.
Use Repository like so:
from fastapi_orm_ext.repository import RepositoryBase
from pydantic import BaseModel
from app.tables import User
# the variant to get async session
from app.utils import get_async_session()
class CreateUserSchema(BaseModel):
name: str
surname: str | None
class UserRepository(RepositoryBase[User]):
# specify the model to interact with
model = User
# choose flush or commit
auto_flush = True
auto_commit = False
# initialize UserRepository
repo = UserRepository(async_session)
# create new record in user table with name Bob and surname NULL
data = CreateUserSchema(name="Bob")
await repo.create(data)
# get all records in User table - in our case only Bob
res: list[User] = await repo.all()
print(res)
To see what else RepositoryBase can do, visit the source code of interface RepositoryBase inheriting from
Installation
pip install fastapi-orm-ext
or
uv add fastapi-orm-ext
or
poetry add fastapi-orm-ext
etc
License
fastapi-orm-ext is distributed under the terms of the MIT license.
Contribution
Install repository:
https://github.com/pkozhem/fastapi-orm-ext.git
Create virtual environment, activate it and install dependencies:
uv venv
source .venv/bin/activate
uv sync
Create new branch from actual tag:
git checkout <tag>
git branch pull-<fix, feat, impr>: Short branch desc
Pull your changes and create pull request:
git pull origin <your_branch_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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_orm_ext-0.0.4.tar.gz.
File metadata
- Download URL: fastapi_orm_ext-0.0.4.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cb323d7475003593fdb28ae804f43cc1b486bada8e78a8486276a374bc55983
|
|
| MD5 |
99e5ab1eb744810a6798efe7cb6721a1
|
|
| BLAKE2b-256 |
13243e3807608887e3caeadb4b3d1c6428af7e78766bf60fa5be483b5ea9bf95
|
File details
Details for the file fastapi_orm_ext-0.0.4-py3-none-any.whl.
File metadata
- Download URL: fastapi_orm_ext-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77bad137d381375d8ce809c35387bd5a8726a711ca848de86e674602d036dc38
|
|
| MD5 |
d5fe29e6c81c46a73eb0f8531d6160df
|
|
| BLAKE2b-256 |
78103b2a189413cb9f6cae787fe72e63426b91bd1b4e698a37f3a2ca9f0619cf
|