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 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


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.5.0.tar.gz (12.4 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.5.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

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

Hashes for fastapi_mongo_setup-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ca942d0bacbcbab78eec67262e0236969b6717bb66184a13abff0cff5e966f46
MD5 dfc4d278d5a97dcafc57eda9043c1da8
BLAKE2b-256 acf5696f234cd05026395f7534e532508220df2ca458e7cc7e1228d97858ed9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_mongo_setup-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcc1e57243cdb24518c3320a1724966f31956dd4e5e9ccee3fb83b0ea97c5be3
MD5 24c3faefebfae05926da872d3a89e0e2
BLAKE2b-256 ae4af296bde65271cc08ad03d19b173932b856258696d5d9d10a6c0d81fd4a18

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