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 Python CLI tool that instantly scaffolds a professional, industry-standard FastAPI + MongoDB project โ including optional JWT authentication, Docker containerization, and test scaffolding.
โก Installation
pip install fastapi-mongo-setup
๐ ๏ธ Usage
Interactive Mode (Recommended)
Just run the command and answer the prompts:
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
Use command-line flags directly:
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
๐ 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 loader
โโโ utils/
โ โโโ db.py # Async Motor connection manager
โ โโโ helpers.py # ObjectId serialization helpers
โโโ tasks/
โ โโโ router.py # GET / POST / DELETE endpoints
โ โโโ schemas.py # Pydantic validation models
โ โโโ service.py # Database CRUD logic
โโโ auth/ # ๐ (with --auth)
โโโ router.py # /auth/register, /auth/login, /auth/me
โโโ schemas.py # UserCreate, UserLogin, Token models
โโโ service.py # Create user, find user by email
โโโ dependencies.py # JWT creation & verification
โโโ utils.py # Password hashing with bcrypt
๐ Running Your Generated Project
With Docker (Recommended) ๐ณ
docker-compose up --build
Without Docker
pip install -r requirements.txt
python main.py
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 |
๐งช Testing (with --test)
Run the pre-built test suite:
pytest
The generated tests cover:
- โ Root endpoint health check
- โ Task CRUD operations (create, list, delete)
- โ
Auth registration & login flow (with
--auth) - โ
Unauthorized access protection (with
--auth)
Linting
ruff check . # Check for issues
ruff format . # Auto-format code
๐ณ Docker Setup (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 |
๐ Why this exists?
Setting up Motor (async MongoDB driver) with FastAPI typically requires repetitive boilerplate: connection managers, lifespans, ObjectId serialization, JWT auth plumbing, Docker configs, and test infrastructure. This tool does all of that for you in one command, providing a clean, modular architecture 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.6.0.tar.gz.
File metadata
- Download URL: fastapi_mongo_setup-0.6.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f5fa3ef2c82b8885444c6291ba77dabcd9a8d40907aeb06aaed3adfab35d677
|
|
| MD5 |
2e4d59bc83b0b77ce9314bf9f2564348
|
|
| BLAKE2b-256 |
297c9451b674100fb618e4e00b96be403cfa45e550209eb15530ac9c8788b44c
|
File details
Details for the file fastapi_mongo_setup-0.6.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_setup-0.6.0-py3-none-any.whl
- Upload date:
- Size: 16.3 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 |
21f5cfd91352406d8acf12372b9896be107b3f9d83b842084b0ef4dc696ae07e
|
|
| MD5 |
89a1fdfba664ba1a358578985c38b007
|
|
| BLAKE2b-256 |
010b52f41b8bf99bed392993ca176a9992e4b2375b828c3f80684bc7bcaae692
|