
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
fastapi-crudrouter-mongodb
Advanced tools
A dynamic FastAPI router that automatically creates CRUD routes for your mongodb models
ā” Create CRUD routes with lighting speed ā”
A dynamic FastAPI router that automatically creates CRUD routes for your Mongodb models
Documentation: https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/
Source Code: https://github.com/pierrod/fastapi-crudrouter-mongodb
Credits :
Base projet and idea : awtkns
Convert _id to id (for previous versions of Pydantic) : mclate github guide
For Pydantic v2 : Stackoverflow
Are you exhausted from constantly rewriting basic CRUD routes? Do you find yourself needing to swiftly prototype features for presentations or hackathons? Well, rejoice! Introducing fastapi-crudrouter-mongodb, your ultimate solution.
As a complement to FastAPI's APIRouter, the FastAPI CRUDRouter for MongoDB š± takes care of the heavy lifting for you. It automatically generates and documents your CRUD routes with minimal effort. Simply provide your model and your database connection, and you're good to go!
pip install fastapi-crudrouter-mongodb
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 typing import Annotated
from fastapi import FastAPI
from fastapi_crudrouter_mongodb import (
ObjectId,
MongoObjectId,
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: Annotated[ObjectId, MongoObjectId] | 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)
fastapi-crudrouter-mongodb offers several functionalities designed to maximize the benefits of your auto-generated CRUD routes. Here are some key highlights:
By default, the CRUDRouter automatically documents all generated routes in accordance with the OpenAPI specification.
The default routes generated by the CRUDRouter are displayed in the OpenAPI documentation generated by the system.
The CRUDRouter can dynamically generate comprehensive documentation based on the provided models.
FAQs
A dynamic FastAPI router that automatically creates CRUD routes for your mongodb models
We found that fastapi-crudrouter-mongodb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.