Start building with FluxCRUD in under 5 minutes
Install Library
pip install fluxcrud
uvicorn for running the server.pip install uvicorn
Create App
main.py:from typing import Optional
from fastapi import FastAPI
from fluxcrud import Flux, Base, Schema
from sqlalchemy.orm import Mapped, mapped_column
# 1. Define Model
class Task(Base):
__tablename__ = "tasks"
id: Mapped[int] = mapped_column(primary_key=True)
title: Mapped[str]
done: Mapped[bool] = mapped_column(default=False)
# 2. Define Schema
class TaskSchema(Schema):
title: str
done: bool
class TaskCreate(Schema):
title: str
class TaskUpdate(Schema):
title: Optional[str] = None
done: Optional[bool] = None
# 3. Initialize Flux
app = FastAPI()
flux = Flux(app, db_url="sqlite+aiosqlite:///app.db")
flux.attach_base(Base)
# 4. Register Resource
flux.register(
model=Task,
schema=TaskSchema,
create_schema=TaskCreate,
update_schema=TaskUpdate,
prefix="/tasks",
tags=["Tasks"]
)