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 โ including an optional JWT authentication system.
โก Installation
pip install fastapi-mongo-setup
๐ ๏ธ Usage
Basic Setup (DB + CRUD)
Navigate to your project folder and run:
mongo-setup
With Authentication ๐
Add a complete JWT auth system (register, login, protected routes):
mongo-setup --auth
๐ Generated Project Structure
Without --auth
your-project/
โโโ .env # MONGODB_URL, DATABASE_NAME, PORT
โโโ requirements.txt # fastapi, motor, pydantic-settings, etc.
โโโ main.py # FastAPI entry point with MongoDB lifespan
โโโ 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
With --auth (adds these files)
โโโ src/
โโโ config.py # Now includes SECRET_KEY, ALGORITHM, etc.
โโโ auth/ # ๐ Complete Auth Module
โโโ 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, get_current_user
โโโ utils.py # Password hashing with bcrypt
Plus auto-updates to:
.envโ addsSECRET_KEY,ALGORITHM,ACCESS_TOKEN_EXPIRE_MINUTESrequirements.txtโ addspython-jose,passlib,bcryptmain.pyโ registers the auth router automatically
๐ Running Your Generated Project
# 1. Install dependencies
pip install -r requirements.txt
# 2. Start the server
python main.py
Open http://localhost:8000/docs to see your Swagger UI with fully functional Tasks CRUD and (if --auth was used) Authentication endpoints!
๐ Auth Endpoints (when using --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 |
๐ Why this exists?
Setting up Motor (async MongoDB driver) with FastAPI typically requires repetitive boilerplate: connection managers, lifespans, ObjectId serialization, and JWT auth plumbing. 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.4.0.tar.gz.
File metadata
- Download URL: fastapi_mongo_setup-0.4.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f59df1c152188a26318e06e31da2c3b09af672df01a5a07f3a726e762c3c9aac
|
|
| MD5 |
4e502cc58f43eb593b49def5f40f3c8d
|
|
| BLAKE2b-256 |
8cba13ef09db0710b087c1eab05d97606faf413ab9e97cdc80e44172b97e8a57
|
File details
Details for the file fastapi_mongo_setup-0.4.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_mongo_setup-0.4.0-py3-none-any.whl
- Upload date:
- Size: 13.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 |
0f63dfa93a1fc3b67cf46b6074ee6925749595d941494cc3c4aa339c69ded3f1
|
|
| MD5 |
e26a6310065d5e653cb855871db681ef
|
|
| BLAKE2b-256 |
e49a8a77596358021bb97a4d096b68e38e7f4e93228f87264e73f42b665e4c58
|