Skip to main content

A CLI tool to auto-generate MongoDB connection boilerplates for FastAPI projects.

Project description

fastapi-mongo-setup ๐Ÿš€

PyPI version Python versions License: MIT

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 โ†’ adds SECRET_KEY, ALGORITHM, ACCESS_TOKEN_EXPIRE_MINUTES
  • requirements.txt โ†’ adds python-jose, passlib, bcrypt
  • main.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_mongo_setup-0.4.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_mongo_setup-0.4.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

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

Hashes for fastapi_mongo_setup-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f59df1c152188a26318e06e31da2c3b09af672df01a5a07f3a726e762c3c9aac
MD5 4e502cc58f43eb593b49def5f40f3c8d
BLAKE2b-256 8cba13ef09db0710b087c1eab05d97606faf413ab9e97cdc80e44172b97e8a57

See more details on using hashes here.

File details

Details for the file fastapi_mongo_setup-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_mongo_setup-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f63dfa93a1fc3b67cf46b6074ee6925749595d941494cc3c4aa339c69ded3f1
MD5 e26a6310065d5e653cb855871db681ef
BLAKE2b-256 e49a8a77596358021bb97a4d096b68e38e7f4e93228f87264e73f42b665e4c58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page