https://github.com/mahimailabs/fluxcrud
FluxCRUD is a easy to use, fast, and modern CRUD framework for FastAPI.
https://github.com/mahimailabs/fluxcrud
async crud fastapi fastapi-crud fluxcrud pydantic pydantic-v2 sqlalchemy
Last synced: 4 months ago
JSON representation
FluxCRUD is a easy to use, fast, and modern CRUD framework for FastAPI.
- Host: GitHub
- URL: https://github.com/mahimailabs/fluxcrud
- Owner: mahimailabs
- License: mit
- Created: 2025-12-08T16:02:19.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-12-21T17:14:37.000Z (6 months ago)
- Last Synced: 2025-12-23T05:14:15.252Z (6 months ago)
- Topics: async, crud, fastapi, fastapi-crud, fluxcrud, pydantic, pydantic-v2, sqlalchemy
- Language: Python
- Homepage: https://fluxcrud.mahimai.dev/
- Size: 1.62 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Modern, High-Performance, Async-First CRUD Framework for FastAPI β‘
---
**FluxCRUD** is a developer-friendly framework designed to eliminate boilerplate when building efficient, scalable APIs with **FastAPI** and **SQLAlchemy 2.0**. It provides a fully typed, async-first experience with built-in best practices like **caching**, **N+1 query prevention (DataLoaders)**, and **automatic extensive pagination**.
## β¨ Features
- **π Async & Fast**: Built on top of `asyncpg`, `aiosqlite`, and `SQLAlchemy 2.0`.
- **π οΈ Zero Boilerplate**: Auto-generates fully typed CRUD routes (Create, Read, Update, Delete, List).
- **β‘ Smart Caching**: Integrated support for **Redis**, **Memcached**, and **In-Memory** caching.
- **π Query Optimization**: Built-in **DataLoaders** to solve N+1 query problems automatically.
- **π Advanced Pagination**: Cursor-based and limit-offset pagination out of the box.
- **π‘οΈ Type Safe**: Deep integration with **Pydantic v2** for robust data validation.
- **π¦ Modular**: Use what you needβRouter, Repository, or the full Framework.
## π¦ Installation
```bash
pip install fluxcrud
# OR with standard extras
pip install "fluxcrud[postgresql,redis]"
```
## π Quick Start
Build a comprehensive API in less than 30 lines of code.
```python
from fastapi import FastAPI
from sqlalchemy.orm import Mapped, mapped_column
from pydantic import BaseModel
from fluxcrud import Flux, Base
# 1. Define your Database Model
class Item(Base):
__tablename__ = "items"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
price: Mapped[float]
# 2. Define Pydantic Schemas
class ItemSchema(BaseModel):
id: int
name: str
price: float
class CreateItemSchema(BaseModel):
name: str
price: float
# 3. Initialize App & Flux
app = FastAPI()
flux = Flux(app, db_url="sqlite+aiosqlite:///:memory:")
flux.attach_base(Base)
# 4. Register Routes
# Auto-generates: GET /items, POST /items, GET /items/{id}, PATCH /items/{id}, DELETE /items/{id}
flux.register(
model=Item,
schema=ItemSchema,
create_schema=CreateItemSchema
)
```
Run it locally:
```bash
uvicorn main:app --reload
```
## π§© Advanced Usage
### Customizing the Repository
Need custom logic? Extend `FluxRepository` seamlessly.
```python
from fluxcrud.core import FluxRepository
class ItemRepository(FluxRepository[Item]):
async def get_expensive_items(self, min_price: float):
query = select(Item).where(Item.price > min_price)
return await self.all(query)
```
### Enabling Caching
FluxCRUD makes caching trivial.
```python
from fluxcrud.cache import RedisBackend
# Configure Redis cache with 60s TTL
flux = Flux(
app,
db_url="...",
cache_backend=RedisBackend("redis://localhost"),
cache_ttl=60
)
```
## π€ Contributing
We welcome contributions! Please check out our [Contributing Guide](CONTRIBUTING.md) to get started.
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.