Skip to main content

A dynamic FastAPI router that automatically creates CRUD routes for your mongodb models

Project description

⚡ Create CRUD routes with lighting speed
A dynamic FastAPI router that automatically creates CRUD routes for your Mongodb models

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

---

Documentation: https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/

Source Code: https://github.com/pierrod/fastapi-crudrouter-mongodb

Credits :


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!

Installation


 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 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)

Advanced Usage

fastapi-crudrouter-mongodb offers several functionalities designed to maximize the benefits of your auto-generated CRUD routes. Here are some key highlights:

  • Automatic Lookups
  • Automatic Embeds
  • Ability to provide Custom out schema
  • Ability to Disable specific routes
  • Ability to Add custom dependencies to specific routes

OpenAPI Support


"Automatic OpenAPI Documentation"

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.

CRUDRouter OpenAPI schema

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

CRUDRouter OpenAPI schema details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-crudrouter-mongodb-0.1.3.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_crudrouter_mongodb-0.1.3-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-crudrouter-mongodb-0.1.3.tar.gz.

File metadata

File hashes

Hashes for fastapi-crudrouter-mongodb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 62e287dc4f2ac6b86a2b98171ab5b760157943bf218f2cba61572aeca67f15bc
MD5 ac6c48c4cac20ea9fe56106c59b259b9
BLAKE2b-256 7dd69a41c45d46e01c32d81a42984495344d56d559b79b2cd9d4af6c6029469a

See more details on using hashes here.

File details

Details for the file fastapi_crudrouter_mongodb-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_crudrouter_mongodb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 83784e2ca96cf67e08a6d12ae07b0e704a7f2e0f8c6324e0cb6eaee93d6d29eb
MD5 ef8f315ea30279c850b985a92929932c
BLAKE2b-256 924a7833505161fdbc3de2e5b6b12955bc0673ccd624e8116d38299f4aae2d36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page