A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.
Project description
FastAPI Repository
A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack. It provides a simple, intuitive, and asynchronous interface for data access using SQLAlchemy.
Key Features
- Async-first: Designed for modern asynchronous Python.
- Simple CRUD:
find,create,update,destroymethods out of the box. - Powerful Filtering: Use Ransack-style operators (
__icontains,__gt, etc.) for complex queries. - Relationship Loading: Control eager (
joinedload) and lazy (lazyload) loading. - Default Scoping: Apply default conditions to all queries.
Installation
pip install fastapi-repository
Quick Start
-
Define a repository for your SQLAlchemy model:
# repositories.py from fastapi_repository import BaseRepository from sqlalchemy.ext.asyncio import AsyncSession from .models import User # Your SQLAlchemy model class UserRepository(BaseRepository): def __init__(self, session: AsyncSession): super().__init__(session, model=User)
-
Use it in your FastAPI application:
# main.py from fastapi import FastAPI, Depends from sqlalchemy.ext.asyncio import AsyncSession from .database import get_session from .repositories import UserRepository app = FastAPI() @app.get("/users/{user_id}") async def get_user(user_id: int, session: AsyncSession = Depends(get_session)): repo = UserRepository(session) user = await repo.find(user_id) return user
Documentation
For a complete guide, including a full tutorial, API reference, and advanced usage, please see the Full Documentation.
Project details
Release history Release notifications | RSS feed
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_repository-0.0.9.tar.gz.
File metadata
- Download URL: fastapi_repository-0.0.9.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
783ac1ccc647b15bd120d8444abc9ca0d1927ea2fd1fe1c2c944f82b95dc7e29
|
|
| MD5 |
405037ba30493b8c45e914224719ec15
|
|
| BLAKE2b-256 |
b6ad2001b649bcc1d90e0707ce470383f9d4dfdd2ccf56297db655e9cdaa275b
|
File details
Details for the file fastapi_repository-0.0.9-py3-none-any.whl.
File metadata
- Download URL: fastapi_repository-0.0.9-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09a1aef71e463cd674ec6b4dc9b260193e085f292b0ee02d81a9f91170ecea28
|
|
| MD5 |
2a12613db1f11cf0fc1aa2e6614f90df
|
|
| BLAKE2b-256 |
d2cf803828d658ee3a5036e0abfdd97246ad6fb154983db096d28e1856b9fe23
|