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 powerful CLI tool that scaffolds production-ready FastAPI + MongoDB projects โ with optional JWT auth, Docker, tests, a resource generator, and auto-start support.
โก 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
mongo-setup # Base setup (DB + CRUD)
mongo-setup --auth # + JWT Authentication
mongo-setup --docker # + Docker containerization
mongo-setup --test # + Pytest tests & Ruff linter
mongo-setup --all # Everything included
๐งฉ Resource Generator (NEW!)
Generate new API modules on the fly โ no more copy-pasting boilerplate:
mongo-setup resource products
mongo-setup resource blog_posts
mongo-setup resource orders
Each generates a complete src/<name>/ module with:
router.pyโ Full CRUD endpoints (POST, GET, GET by ID, PUT, DELETE)schemas.pyโ Pydantic Create, Update, and Response modelsservice.pyโ MongoDB CRUD operations with serialization
๐ Generated Project Structure
your-project/
โโโ .env # Environment variables (auto-populated)
โโโ requirements.txt # All dependencies
โโโ main.py # FastAPI entry point with MongoDB lifespan
โโโ Dockerfile # ๐ณ (with --docker)
โโโ docker-compose.yml # ๐ณ (with --docker)
โโโ .dockerignore # ๐ณ (with --docker)
โโโ pytest.ini # ๐งช (with --test)
โโโ .ruff.toml # ๐งน (with --test)
โโโ tests/ # ๐งช (with --test)
โ โโโ conftest.py # Async test client setup
โ โโโ test_tasks.py # Task endpoint tests
โ โโโ test_auth.py # Auth endpoint tests (with --auth)
โโโ src/
โโโ config.py # Pydantic Settings configuration
โโโ utils/
โ โโโ db.py # Async Motor connection manager
โ โโโ helpers.py # ObjectId serialization helpers
โโโ tasks/ # Default CRUD module
โ โโโ router.py
โ โโโ schemas.py
โ โโโ service.py
โโโ auth/ # ๐ (with --auth)
โ โโโ router.py
โ โโโ schemas.py
โ โโโ service.py
โ โโโ dependencies.py
โ โโโ utils.py
โโโ <your_resource>/ # ๐งฉ (with resource command)
โโโ router.py # Full CRUD (POST, GET, GET/:id, PUT, DELETE)
โโโ schemas.py # Create, Update, Response models
โโโ service.py # MongoDB operations
๐ Quick Start
With Docker ๐ณ
mongo-setup --all
docker-compose up --build
Without Docker
mongo-setup --all
pip install -r requirements.txt
python main.py
Add a New Resource
mongo-setup resource products
Then add to your main.py:
from src.products.router import router as products_router
app.include_router(products_router)
Open http://localhost:8000/docs to see your Swagger UI!
๐ Auth Endpoints (with --auth)
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/register |
Create a new user account | โ |
| POST | /auth/login |
Get a JWT access token | โ |
| GET | /auth/me |
Get current user's profile | โ Bearer |
๐งฉ Resource Generator Endpoints
Each mongo-setup resource <name> generates:
| 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 (with --test)
pytest # Run all tests
ruff check . # Lint code
ruff format . # Auto-format code
๐ณ Docker (with --docker)
| File | Purpose |
|---|---|
Dockerfile |
Python 3.11-slim image with your FastAPI app |
docker-compose.yml |
Orchestrates FastAPI + MongoDB 7 containers |
.dockerignore |
Keeps the Docker image clean and small |
๐ค 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.8.1.tar.gz.
File metadata
- Download URL: fastapi_mongo_setup-0.8.1.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ce2b21123024e84de655e9a8afabb7f993893bfba3b857ee632839947007528
|
|
| MD5 |
7853156fa11eb7dd935c3f09c1dce528
|
|
| BLAKE2b-256 |
5d86c28eca35cdf2660c167ff95579d3982f2fc2d37bcd48c29fa25ee9d8937d
|
File details
Details for the file fastapi_mongo_setup-0.8.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_setup-0.8.1-py3-none-any.whl
- Upload date:
- Size: 19.0 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 |
776c26590c44af47cebf3b57a4d87f045c390eb94e0c5570c16289c72a493eb0
|
|
| MD5 |
7d98f99156d9a640e377f2abe461f4fa
|
|
| BLAKE2b-256 |
4a648e0e4d1194eb647e5d7b8d58e184158098d3ee3a24c56fa8684977360179
|