A CLI tool to auto-generate MongoDB connection boilerplates for FastAPI projects.
Project description
fastapi-mongo-setup 🚀
Stop writing MongoDB boilerplate for FastAPI!
fastapi-mongo-setup is a fast, lightweight Python CLI tool that instantly scaffolds a professional, industry-standard FastAPI + MongoDB project structure. It generates async DB connections, Pydantic settings, and a fully functional CRUD router in one command.
⚡ Installation
Install globally or within your virtual environment:
pip install fastapi-mongo-setup
🛠️ Usage
Navigate to the root of your empty (or existing) FastAPI project and run:
mongo-setup
What does this command do?
Instantly, it generates the following modular architecture:
fastapi-project/
├── .env # Auto-populated with MONGODB_URL and DATABASE_NAME
├── requirements.txt # Dependencies (fastapi, motor, pydantic-settings, etc)
├── main.py # FastAPI entry point with MongoDB Lifespan logic
└── src/
├── config.py # Configuration loader using Pydantic Settings
├── utils/ # Database core
│ ├── db.py # Asynchronous Motor connection manager
│ └── helpers.py # MongoDB ObjectId Serialization helpers
└── tasks/ # Complete pre-built API module
├── router.py # GET/POST/DELETE endpoints
├── schemas.py # Pydantic validation models
└── service.py # Database CRUD logic
🚀 Running Your Generated Project
Once the files are created, just install the dependencies and start the built-in demo server!
# 1. Install required packages
pip install -r requirements.txt
# 2. Run the server
python main.py
Go to http://localhost:8000/docs to see your automatically generated Swagger UI with a fully functional Tasks API connected to your MongoDB!
🏗 Why this exists?
Setting up Motor (the async MongoDB driver) with FastAPI usually requires copy-pasting code to handle connections, lifespans, and fixing ObjectId serialization errors. This minimalist tool does all of that for you, providing a clean abstraction layer and a modular structure designed for scaling.
🤝 Contributing
Found a bug or want to request a feature? Feel free to open an issue or submit a pull request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_mongo_setup-0.3.2.tar.gz.
File metadata
- Download URL: fastapi_mongo_setup-0.3.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac16c52d09ee1a4447e9f44836ae92f496989a2cae2b1902a33ad7b9b368013d
|
|
| MD5 |
d76247069ef187a975229396e571bec2
|
|
| BLAKE2b-256 |
f34e9e0b32e1f814653a05b915d126a37ba0069d3c7b895d733e3818879ecd77
|
File details
Details for the file fastapi_mongo_setup-0.3.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_setup-0.3.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16b084e6873fca7207b4fdc2d9344678c5a80f3676b6b59d7ce9109e56a38d4d
|
|
| MD5 |
7082d1f051b3b81c63b17f6bbeaaef8d
|
|
| BLAKE2b-256 |
7adaee2f624bfedb5faf083a498e53c9bf0d3c52a4f61fc84303c42bbb601d0b
|