⚡ Instant CRUD APIs from Pydantic Models ⚡
Build a fully working FastAPI CRUD API in 10 seconds.
🚀 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 🌱.
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.
The CRUDRouter can dynamically generate comprehensive documentation based on the provided models.
Credits :
-
Base projet and idea : awtkns
-
Convert _id to id (for previous versions of Pydantic) : mclate github guide
-
For Pydantic v2 : Stackoverflow
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_crudrouter_mongodb-1.0.1.tar.gz | 20.2 kB | Without provenance | Details for fastapi_crudrouter_mongodb-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_crudrouter_mongodb-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for fastapi_crudrouter_mongodb-1.0.1-py3-none-any.whl |
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
|
Security for fastapi-crudrouter-mongodb 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.