Home
âš¡ Instant CRUD APIs from Pydantic Models âš¡ Build a fully working FastAPI CRUD API in 10 seconds.
🚀 10-second example¶
$ pip install fastapi-crudrouter-mongodb
---> 100%
from fastapi import FastAPI
import motor.motor_asyncio
from fastapi_crudrouter_mongodb import (
ObjectIdType,
MongoModel,
CRUDRouter,
)
# Database connection using motor
client = motor.motor_asyncio.AsyncIOMotorClient("mongodb://localhost:27017/local")
# store the database in a global variable
db = client.local
# Database Model
class UserModel(MongoModel):
id: ObjectIdType | None = None
name: str
email: str
# Instantiating the CRUDRouter
users_router = CRUDRouter(
model=UserModel,
db=db,
collection_name="users",
prefix="/users",
tags=["users"],
)
# Instantiating the FastAPI app
app = FastAPI()
app.include_router(users_router)
✨ What you get instantly¶
| HTTP Verb | Path | Description |
|---|---|---|
GET |
/users | List all users |
POST |
/users | Create a new user |
GET |
/users/{id} | Get a user by id |
PUT |
/users/{id} | Update a user by id |
PATCH |
/users/{id} | Partially update a user by id |
DELETE |
/users/{id} | Delete a user by id |
No routing. No boilerplate. No repetition.
The CRUDRouter automatically generates all the necessary routes for your models.
🔥 Why this exists¶
FastAPI is great, but CRUD is repetitive.
This library removes the boring parts so you can focus on your product.
âš¡ Get started¶
👉 Jump to the Quickstart in 2 minutes
OpenAPI Support¶
Automatic OpenAPI Documentation
By default, the CRUDRouter automatically documents all generated routes in accordance with the OpenAPI specification.

The CRUDRouter can dynamically generate comprehensive documentation based on the provided models.

Credits : - FastAPI
-
Base projet and idea : awtkns
-
Convert _id to id (for previous versions of Pydantic) : mclate github guide
-
For Pydantic v2 : Stackoverflow