Skip to main content

⚡ Instant CRUD APIs from Pydantic Models ⚡
Build a fully working FastAPI CRUD API in 10 seconds.

Monthly Downloads Shield Badge Weekly Downloads Shield Badge Python Version Python Version

---

🚀 Features

  • Auto-generate CRUD endpoints from Pydantic models
  • Works with FastAPI
  • MongoDB support
  • Fully extendable
  • Zero boilerplate

⚡ Example

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

!!!tip "No routing. No boilerplate. No repetition." The CRUDRouter automatically generates all the necessary routes for your models.


Install

Requires Python >=3.10.

 pip install fastapi-crudrouter-mongodb

Basic Usage


I will provide more examples in the future, but for now, here is a basic example of how to use the FastAPI CRUDRouter for Mongodb :seedling:.

from fastapi import FastAPI
from fastapi_crudrouter_mongodb import (
    ObjectIdType,
    MongoModel,
    CRUDRouter,
)
import motor.motor_asyncio

# 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
    password: str


# Instantiating the CRUDRouter, and a lookup for the messages
# a User is a model that contains a list of embedded addresses and related to multiple messages

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)

🧠 Why

FastAPI is amazing, but CRUD is repetitive.

This library removes boilerplate so you can focus on your product

📚 Documentation

👉 Full docs: Right here


Automatic OpenAPI Documentation

By default, the CRUDRouter automatically documents all generated routes in accordance with the OpenAPI specification.

CRUDRouter OpenAPI schema

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

CRUDRouter OpenAPI schema details


Credits :

Metadata

Release files for fastapi-crudrouter-mongodb 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-crudrouter-mongodb 1.0.1
File Size Uploaded
fastapi_crudrouter_mongodb-1.0.1.tar.gz 20.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-crudrouter-mongodb 1.0.1
File Interpreter ABI Platform
fastapi_crudrouter_mongodb-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 47.4 kB

Release files / fastapi_crudrouter_mongodb-1.0.1.tar.gz

Download URL fastapi_crudrouter_mongodb-1.0.1.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a9064cb51896ec8b1aab8dcfc09b599a98369f97d91e49d1c54c3bbef002e4df
BLAKE2b-256 checksum
How to use checksums
2cd1fc95c24981fe32c002a852ee921ead9956bfba860af6ce98f5c74a545443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / fastapi_crudrouter_mongodb-1.0.1-py3-none-any.whl

Download URL fastapi_crudrouter_mongodb-1.0.1-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f51e770bb190349b0bbd6e19be759dca11de9dfe5a86d8a5f730d3bd0651598
BLAKE2b-256 checksum
How to use checksums
b6bfe5563c9fb525bfa2623b7297b604fdba48f29efc7f336654db6f5f64ef37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

1 release file

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page