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 and Docker containerization.
โก 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
Flag Mode
Or use command-line flags directly:
mongo-setup # Base setup (DB + CRUD)
mongo-setup --auth # + JWT Authentication
mongo-setup --docker # + Docker containerization
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)
โโโ 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
This starts both your FastAPI app and a MongoDB instance automatically. No local MongoDB installation needed!
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 |
๐ณ 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 |
Excludes unnecessary files from the Docker build |
๐ Why this exists?
Setting up Motor (async MongoDB driver) with FastAPI typically requires repetitive boilerplate: connection managers, lifespans, ObjectId serialization, JWT auth plumbing, and Docker configs. 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.5.0.tar.gz.
File metadata
- Download URL: fastapi_mongo_setup-0.5.0.tar.gz
- Upload date:
- Size: 12.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 |
ca942d0bacbcbab78eec67262e0236969b6717bb66184a13abff0cff5e966f46
|
|
| MD5 |
dfc4d278d5a97dcafc57eda9043c1da8
|
|
| BLAKE2b-256 |
acf5696f234cd05026395f7534e532508220df2ca458e7cc7e1228d97858ed9f
|
File details
Details for the file fastapi_mongo_setup-0.5.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_setup-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.6 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 |
fcc1e57243cdb24518c3320a1724966f31956dd4e5e9ccee3fb83b0ea97c5be3
|
|
| MD5 |
24c3faefebfae05926da872d3a89e0e2
|
|
| BLAKE2b-256 |
ae4af296bde65271cc08ad03d19b173932b856258696d5d9d10a6c0d81fd4a18
|