fastapi-crudrouter-mongodb


Namefastapi-crudrouter-mongodb JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/pierrod/fastapi-crudrouter-mongodb
SummaryA dynamic FastAPI router that automatically creates CRUD routes for your mongodb models
upload_time2024-08-21 21:15:51
maintainerNone
docs_urlNone
authorPierre DUVEAU
requires_python>=3.7
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="./docs/assets/img/logo-long-color.png" height="200" />
</p>
<p align="center">
  <em>⚡ Create CRUD routes with lighting speed</em> ⚡</br>
  <sub>A dynamic FastAPI router that automatically creates CRUD routes for your Mongodb models</sub>
</p>

<div align="center">

![Monthly Downloads Shield Badge](https://img.shields.io/pypi/dm/fastapi-crudrouter-mongodb?color=50b052&style=for-the-badge) ![Weekly Downloads Shield Badge](https://img.shields.io/pypi/dw/fastapi-crudrouter-mongodb?color=50b052&style=for-the-badge) ![Python Version](https://img.shields.io/pypi/v/fastapi-crudrouter-mongodb?color=50b052&style=for-the-badge) ![Python Version](https://img.shields.io/pypi/pyversions/fastapi-crudrouter-mongodb?color=3776AB&style=for-the-badge&logo=python&logoColor=white)

</div>
---

**Documentation**: [https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/)

**Source Code**: [https://github.com/pierrod/fastapi-crudrouter-mongodb](https://github.com/pierrod/fastapi-crudrouter-mongodb)

**Credits** :

- Base projet and idea : [awtkns](https://github.com/awtkns/fastapi-crudrouter)

- Convert \_id to id (for previous versions of Pydantic) : [mclate github guide](https://github.com/tiangolo/fastapi/issues/1515)

- For Pydantic v2 : [Stackoverflow](https://stackoverflow.com/questions/76686267/what-is-the-new-way-to-declare-mongo-objectid-with-pydantic-v2-0)

---

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](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/), your ultimate solution.

As a complement to FastAPI's APIRouter, the [FastAPI](https://fastapi.tiangolo.com/) 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:.

```py linenums="1"
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](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/assets/img/openapi-basic-example.png)


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

![CRUDRouter OpenAPI schema details](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/assets/img/openapi-basic-example-details.png)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pierrod/fastapi-crudrouter-mongodb",
    "name": "fastapi-crudrouter-mongodb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Pierre DUVEAU",
    "author_email": "pierre@duveau.org",
    "download_url": "https://files.pythonhosted.org/packages/45/f4/1b0b8d26ace4d08e97e2f6d8d42bf6ea95f82fd1500e41d5026b91759213/fastapi-crudrouter-mongodb-0.1.2.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"./docs/assets/img/logo-long-color.png\" height=\"200\" />\n</p>\n<p align=\"center\">\n  <em>\u26a1 Create CRUD routes with lighting speed</em> \u26a1</br>\n  <sub>A dynamic FastAPI router that automatically creates CRUD routes for your Mongodb models</sub>\n</p>\n\n<div align=\"center\">\n\n![Monthly Downloads Shield Badge](https://img.shields.io/pypi/dm/fastapi-crudrouter-mongodb?color=50b052&style=for-the-badge) ![Weekly Downloads Shield Badge](https://img.shields.io/pypi/dw/fastapi-crudrouter-mongodb?color=50b052&style=for-the-badge) ![Python Version](https://img.shields.io/pypi/v/fastapi-crudrouter-mongodb?color=50b052&style=for-the-badge) ![Python Version](https://img.shields.io/pypi/pyversions/fastapi-crudrouter-mongodb?color=3776AB&style=for-the-badge&logo=python&logoColor=white)\n\n</div>\n---\n\n**Documentation**: [https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/)\n\n**Source Code**: [https://github.com/pierrod/fastapi-crudrouter-mongodb](https://github.com/pierrod/fastapi-crudrouter-mongodb)\n\n**Credits** :\n\n- Base projet and idea : [awtkns](https://github.com/awtkns/fastapi-crudrouter)\n\n- Convert \\_id to id (for previous versions of Pydantic) : [mclate github guide](https://github.com/tiangolo/fastapi/issues/1515)\n\n- For Pydantic v2 : [Stackoverflow](https://stackoverflow.com/questions/76686267/what-is-the-new-way-to-declare-mongo-objectid-with-pydantic-v2-0)\n\n---\n\nAre 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](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/), your ultimate solution.\n\nAs a complement to FastAPI's APIRouter, the [FastAPI](https://fastapi.tiangolo.com/) CRUDRouter for MongoDB \ud83c\udf31 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!\n\n\n## Installation\n\n---\n\n\n```\n pip install fastapi-crudrouter-mongodb\n```\n\n\n## Basic Usage\n\n---\n\nI 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:.\n\n```py linenums=\"1\"\nfrom typing import Annotated\nfrom fastapi import FastAPI\nfrom fastapi_crudrouter_mongodb import (\n    ObjectId,\n    MongoObjectId,\n    MongoModel,\n    CRUDRouter,\n)\nimport motor.motor_asyncio\n\n# Database connection using motor\nclient = motor.motor_asyncio.AsyncIOMotorClient(\"mongodb://localhost:27017/local\")\n\n# store the database in a global variable\ndb = client.local\n\n# Database Model\nclass UserModel(MongoModel):\n    id: Annotated[ObjectId, MongoObjectId] | None = None\n    name: str\n    email: str\n    password: str\n\n\n# Instantiating the CRUDRouter, and a lookup for the messages\n# a User is a model that contains a list of embedded addresses and related to multiple messages\n\nusers_router = CRUDRouter(\n    model=UserModel,\n    db=db,\n    collection_name=\"users\",\n    prefix=\"/users\",\n    tags=[\"users\"],\n)\n\n# Instantiating the FastAPI app\napp = FastAPI()\napp.include_router(users_router)\n```\n\n## Advanced Usage\n\nfastapi-crudrouter-mongodb offers several functionalities designed to maximize the benefits of your auto-generated CRUD routes. Here are some key highlights:\n\n- Automatic Lookups \n- Automatic Embeds\n- Ability to provide **Custom** out schema\n- Ability to **Disable** specific routes\n- Ability to **Add custom dependencies** to specific routes\n\n\n## OpenAPI Support\n\n---\n\n### \"Automatic OpenAPI Documentation\"\n\n>By default, the CRUDRouter automatically documents all generated routes in accordance with the OpenAPI specification.\n\nThe default routes generated by the CRUDRouter are displayed in the OpenAPI documentation generated by the system.\n\n![CRUDRouter OpenAPI schema](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/assets/img/openapi-basic-example.png)\n\n\nThe CRUDRouter can dynamically generate comprehensive documentation based on the provided models.\n\n![CRUDRouter OpenAPI schema details](https://pierrod.github.io/fastapi-crudrouter-mongodb-doc/assets/img/openapi-basic-example-details.png)\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A dynamic FastAPI router that automatically creates CRUD routes for your mongodb models",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/pierrod/fastapi-crudrouter-mongodb"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea72bfa865600db01f5e32825be5341e5a2bcd974ffda423c8b78f9940094a44",
                "md5": "66743a48c8e9e1f5776a56a389e78e73",
                "sha256": "1a71a89fd464bab825dc44d6ab00ec32c7cae982f0a1a8d8b3a96e9c6faf338f"
            },
            "downloads": -1,
            "filename": "fastapi_crudrouter_mongodb-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66743a48c8e9e1f5776a56a389e78e73",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 18794,
            "upload_time": "2024-08-21T21:15:48",
            "upload_time_iso_8601": "2024-08-21T21:15:48.861689Z",
            "url": "https://files.pythonhosted.org/packages/ea/72/bfa865600db01f5e32825be5341e5a2bcd974ffda423c8b78f9940094a44/fastapi_crudrouter_mongodb-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45f41b0b8d26ace4d08e97e2f6d8d42bf6ea95f82fd1500e41d5026b91759213",
                "md5": "78a7b040ad7595e43ab059ba9e912b91",
                "sha256": "43c69efee69f8da68a663862228d7b7f6944a2c67c83909548890fca674f9a46"
            },
            "downloads": -1,
            "filename": "fastapi-crudrouter-mongodb-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "78a7b040ad7595e43ab059ba9e912b91",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13515,
            "upload_time": "2024-08-21T21:15:51",
            "upload_time_iso_8601": "2024-08-21T21:15:51.319609Z",
            "url": "https://files.pythonhosted.org/packages/45/f4/1b0b8d26ace4d08e97e2f6d8d42bf6ea95f82fd1500e41d5026b91759213/fastapi-crudrouter-mongodb-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-21 21:15:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pierrod",
    "github_project": "fastapi-crudrouter-mongodb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastapi-crudrouter-mongodb"
}
        
Elapsed time: 0.29182s