A CLI tool to auto-generate MongoDB connection boilerplates for FastAPI projects.
Project description
███████╗ █████╗ ███████╗████████╗ ███╗ ███╗ ██████╗ ███╗ ██╗ ██████╗ ██████╗
██╔════╝██╔══██╗██╔════╝╚══██╔══╝ ████╗ ████║██╔═══██╗████╗ ██║██╔════╝ ██╔═══██╗
█████╗ ███████║███████╗ ██║ █████╗██╔████╔██║██║ ██║██╔██╗ ██║██║ ███╗██║ ██║
██╔══╝ ██╔══██║╚════██║ ██║ ╚════╝██║╚██╔╝██║██║ ██║██║╚██╗██║██║ ██║██║ ██║
██║ ██║ ██║███████║ ██║ ██║ ╚═╝ ██║╚██████╔╝██║ ╚████║╚██████╔╝╚██████╔╝
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝
The Problem
Every new FastAPI + MongoDB project starts the same way — copy-pasting the same motor connection setup, the same Pydantic schemas, the same CRUD boilerplate, the same JWT auth scaffold. It's tedious, error-prone, and a waste of time.
fastapi-mongo-setup is a CLI that eliminates all of it. One command gives you a clean, production-ready project structure with async MongoDB, optional JWT auth, Docker, tests, and a resource generator — so you can skip straight to building.
Installation
pip install fastapi-mongo-setup
Usage
Interactive Mode (Recommended)
mongo-setup
Welcome to fastapi-mongo-setup!
Include JWT Authentication? (y/N): y
Include Docker setup? (y/N): y
Include Test scaffolding? (y/N): y
Flag Mode
| Command | What you get |
|---|---|
mongo-setup |
Base setup — DB connection + CRUD |
mongo-setup --auth |
+ JWT Authentication |
mongo-setup --docker |
+ Docker containerization |
mongo-setup --test |
+ Pytest tests & Ruff linter |
mongo-setup --all |
Everything — full production stack |
Resource Generator
Generate complete API modules on the fly — no copy-pasting:
mongo-setup resource products
mongo-setup resource blog_posts
mongo-setup resource orders
Each command creates a full src/<name>/ module with router.py, schemas.py, and service.py. Then register it in main.py:
from src.products.router import router as products_router
app.include_router(products_router)
Generated Project Structure
your-project/
├── .env
├── requirements.txt
├── main.py # FastAPI entry point with MongoDB lifespan
├── Dockerfile # (--docker)
├── docker-compose.yml # (--docker)
├── pytest.ini # (--test)
├── .ruff.toml # (--test)
├── tests/ # (--test)
│ ├── conftest.py
│ ├── test_tasks.py
│ └── test_auth.py # (--auth)
└── src/
├── config.py
├── utils/
│ ├── db.py # Async Motor connection manager
│ └── helpers.py # ObjectId serialization helpers
├── tasks/ # Default CRUD module
├── auth/ # (--auth)
│ ├── router.py
│ ├── schemas.py
│ ├── service.py
│ ├── dependencies.py
│ └── utils.py
└── <your_resource>/ # (resource generator)
├── router.py
├── schemas.py
└── service.py
Quick Start
With Docker
mongo-setup --all
docker-compose up --build
Without Docker
mongo-setup --all
pip install -r requirements.txt
python main.py
Open http://localhost:8000/docs — your Swagger UI is ready.
Auth Endpoints (--auth)
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/auth/register |
Create a new user account | No |
POST |
/auth/login |
Get a JWT access token | No |
GET |
/auth/me |
Get current user profile | Yes (Bearer) |
Resource Endpoints (per generated resource)
| Method | Endpoint | Description |
|---|---|---|
POST |
/<name>/ |
Create item |
GET |
/<name>/ |
List all items |
GET |
/<name>/{id} |
Get by ID |
PUT |
/<name>/{id} |
Update item |
DELETE |
/<name>/{id} |
Delete item |
Testing (--test)
pytest # Run all tests
ruff check . # Lint
ruff format . # Auto-format
Docker (--docker)
| File | Purpose |
|---|---|
Dockerfile |
Python 3.11-slim image with your FastAPI app |
docker-compose.yml |
Orchestrates FastAPI + MongoDB 7 containers |
.dockerignore |
Keeps the image lean and clean |
Contributing
Found a bug or want a new feature? Open an issue or submit a PR — contributions are welcome.
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.8.3.tar.gz.
File metadata
- Download URL: fastapi_mongo_setup-0.8.3.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de9bae7bfdf65b7ea6a252ef12daaf66ce1525aaea540161c7b53fdd3757e1df
|
|
| MD5 |
0b8af2cc8cb87b445ef2b97676c6e84f
|
|
| BLAKE2b-256 |
2b568351041bf46a785208a46edc8c69a8ab5a7c54afca4e3dc0ab2945c5fd0f
|
File details
Details for the file fastapi_mongo_setup-0.8.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_setup-0.8.3-py3-none-any.whl
- Upload date:
- Size: 19.2 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 |
f86d7c3da2e6172b6aaec1c7da726c6b8e99b28526ff99b532527ce2a1bee6d6
|
|
| MD5 |
35b725ce277d1acff6cf48e664b52fcd
|
|
| BLAKE2b-256 |
c0b8ce487e4d63ec6e0758dd7805d28d00b48ee06a7624123886013a02dfb2c9
|