Skip to main content

A powerful CLI tool for generating production-ready FastAPI applications with SQLAlchemy and MongoDB support

Project description

FastAPI Template CLI

PyPI version Python 3.8+ FastAPI License: MIT Code style: black


๐Ÿš€ Production-ready FastAPI scaffolding with SQLAlchemy & MongoDB support


๐Ÿ“– Documentation โ€ข ๐Ÿ”ง Installation โ€ข ๐ŸŽฏ Templates โ€ข ๐Ÿ—„๏ธ Backends โ€ข ๐Ÿค Contributing


โœจ Features

๐Ÿ—๏ธ Templates ๐Ÿ—„๏ธ Databases ๐Ÿ›ก๏ธ Security ๐Ÿณ DevOps
3 Templates 2 Backends JWT Auth Docker
Minimal โ†’ Full-stack SQLAlchemy + MongoDB FastAPI Users CI/CD Ready

๐ŸŽฏ Template Options

Template Purpose Features Best For
๐ŸŸข Minimal Learning & Prototyping Single file, basic setup Beginners, quick demos
๐ŸŸก API Only REST APIs & Microservices Modular structure, testing APIs, microservices
๐Ÿ”ต Full-Stack Production Applications Docker, migrations, auth Production deployments

๐Ÿ—„๏ธ Backend Support

SQLAlchemy Beanie (MongoDB)
PostgreSQL ๐Ÿ˜ MongoDB ๐Ÿƒ
MySQL ๐Ÿฌ Async/await โšก
SQLite ๐Ÿ“ฑ JSON Schema โœ…
Alembic ๐Ÿ”„ Aggregation ๐Ÿ“Š

๐Ÿš€ Quick Start

๐Ÿ“ฆ Installation

# From PyPI (recommended)
pip install fastapi-template-cli

# From source
git clone https://github.com/Sohail342/fastapi-template.git
cd cli-tool && pip install -e .

โšก Create Your First Project

# Create a production-ready API
fastapi-template new ecommerce-api --template fullstack --backend sqlalchemy

# MongoDB-powered analytics API
fastapi-template new analytics-api --template api_only --backend beanie

# Simple microservice
fastapi-template new user-service --template api_only --backend sqlalchemy

๐Ÿ› ๏ธ Development Setup

cd your-project-name
pip install -r requirements.txt

# SQLAlchemy: Run migrations
alembic upgrade head

# Start development server
uvicorn app.main:app --reload

๐Ÿ“‹ CLI Reference

๐Ÿ”ง Command Structure

fastapi-template new PROJECT_NAME [OPTIONS]

โš™๏ธ Options

Option Values Default Description
--template minimal, api_only, fullstack minimal Project template type
--backend sqlalchemy, beanie sqlalchemy Database backend
--auth flag - Include authentication setup

๐ŸŽฏ Usage Examples

# Full-stack with PostgreSQL
fastapi-template new ecommerce-api --template fullstack --backend sqlalchemy

# API-only with MongoDB
fastapi-template new analytics-api --template api_only --backend beanie

# Minimal with SQLite
fastapi-template new simple-api --template minimal --backend sqlalchemy

# With authentication
fastapi-template new social-app --template fullstack --backend beanie --auth

๐Ÿ—„๏ธ Backend Configuration

๐Ÿ˜ SQLAlchemy Backend

โœ… Features:

  • PostgreSQL, MySQL, SQLite support
  • SQLAlchemy 2.0+ ORM
  • Alembic migrations
  • Connection pooling
  • Transaction support

๐Ÿ“ฆ Dependencies:

sqlalchemy>=2.0.0
alembic>=1.12.0
psycopg2-binary>=2.9.0  # PostgreSQL
# or
pymysql>=1.1.0         # MySQL

โš™๏ธ Environment:

DATABASE_URL=postgresql://user:password@localhost/dbname
# or
DATABASE_URL=sqlite:///./app.db

๐Ÿƒ Beanie Backend (MongoDB)

โœ… Features:

  • MongoDB with async/await
  • Beanie ODM
  • JSON Schema validation
  • Automatic indexing
  • Aggregation pipelines

๐Ÿ“ฆ Dependencies:

beanie>=1.23.0
motor>=3.3.0
pymongo>=4.6.0

โš™๏ธ Environment:

DATABASE_URL=mongodb://localhost:27017/your_db_name

๐Ÿ—๏ธ Project Structure

SQLAlchemy Backend

๐Ÿ“ ecommerce-api/
โ”œโ”€โ”€ ๐Ÿ“„ app/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ api/
โ”‚   โ”‚   โ””โ”€โ”€ api_v1/
โ”‚   โ”‚       โ””โ”€โ”€ endpoints/
โ”‚   โ”‚           โ”œโ”€โ”€ users.py
โ”‚   โ”‚           โ””โ”€โ”€ items.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ crud/
โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ item.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ db/
โ”‚   โ”‚   โ”œโ”€โ”€ database.py
โ”‚   โ”‚   โ””โ”€โ”€ base.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ models/
โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ item.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ schemas/
โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ item.py
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ main.py
โ”œโ”€โ”€ ๐Ÿ“ tests/
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt
โ”œโ”€โ”€ ๐Ÿ“„ Dockerfile
โ”œโ”€โ”€ ๐Ÿ“„ docker-compose.yml
โ””โ”€โ”€ ๐Ÿ“„ .env.example

Beanie Backend

๐Ÿ“ analytics-api/
โ”œโ”€โ”€ ๐Ÿ“„ app/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ api/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ crud/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ db/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ models/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ schemas/
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ main.py
โ”œโ”€โ”€ ๐Ÿ“ tests/
โ””โ”€โ”€ ๐Ÿ“„ requirements.txt

๐Ÿงช Testing

# Run all tests
pytest

# With coverage
pytest --cov=app tests/

# Run specific test
pytest tests/test_users.py -v

๐Ÿณ Docker Support

Quick Start with Docker

# Build and run with Docker
docker-compose up --build

# Or run standalone
docker build -t my-api .
docker run -p 8000:8000 my-api

Docker Compose Services

Service Port Description
app 8000 FastAPI application
db 5432 PostgreSQL database
redis 6379 Redis cache

๐Ÿ› ๏ธ Development

๐Ÿ”ง Setup Development Environment

git clone https://github.com/Sohail342/fastapi-template.git
cd cli-tool

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
ruff format .
ruff check .

๐Ÿ“ Environment Variables

Create .env file:

# Database
DATABASE_URL=postgresql://user:password@localhost/dbname

# Security (auto-generated if empty)
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

# Redis (optional)
REDIS_URL=redis://localhost:6379

# Email (optional)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-password

๐Ÿšจ Troubleshooting

๐Ÿ” Common Issues

Database Connection

# PostgreSQL
sudo service postgresql start
psql -c "CREATE DATABASE myapp;"

# MongoDB
sudo service mongod start
mongosh --eval "use myapp;"

Migration Issues

# Reset migrations (SQLAlchemy)
alembic downgrade base
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head

Import Errors

# Ensure all dependencies
pip install -r requirements.txt

# Check Python version
python --version  # Should be 3.8+

๐Ÿ“ž Getting Help


๐Ÿค Contributing

We welcome contributions! Here's how to get started:

๐Ÿ”„ Contribution Workflow

  1. Fork & Clone

    git clone https://github.com/Sohail342/fastapi-template.git
    cd cli-tool
    
  2. Setup Environment

    python -m venv venv
    source venv/bin/activate
    pip install -e ".[dev]"
    
  3. Create Feature Branch

    git checkout -b feature/amazing-feature
    
  4. Make Changes

    • Add new templates/backends
    • Update documentation
    • Add comprehensive tests
  5. Test Your Changes

    pytest
    # Test template generation
    fastapi-template new test-project --template fullstack --backend sqlalchemy
    
  6. Submit PR

    git commit -m "Add amazing feature"
    git push origin feature/amazing-feature
    

๐ŸŽฏ Contribution Ideas

  • ๐Ÿ†• New Backends: Django ORM, Tortoise ORM, Prisma
  • ๐Ÿงฉ New Templates: GraphQL API, Microservices, Serverless
  • ๐ŸŽจ UI Templates: React frontend, Vue.js integration
  • ๐Ÿ”ง Tools: Database seeders, API documentation generators

๐Ÿ“‹ Guidelines

  • โœ… Follow PEP 8 style guidelines
  • โœ… Add tests for new features
  • โœ… Update documentation
  • โœ… Ensure all tests pass
  • โœ… Use meaningful commit messages

๐Ÿ“Š Stats & Badges

PyPI - Downloads PyPI - Python Version GitHub stars GitHub forks


๐Ÿ† Showcase

Built with FastAPI Template CLI

Project Template Backend Description
E-commerce API Full-stack SQLAlchemy Production e-commerce backend
Analytics Service API Only Beanie Real-time data analytics
User Management API Only SQLAlchemy Microservice architecture

Made with โค๏ธ by the FastAPI community

โญ Star us on GitHub to support development!

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_template_cli-1.2.3.tar.gz (55.7 kB view details)

Uploaded Source

Built Distribution

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

fastapi_template_cli-1.2.3-py3-none-any.whl (72.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_template_cli-1.2.3.tar.gz.

File metadata

  • Download URL: fastapi_template_cli-1.2.3.tar.gz
  • Upload date:
  • Size: 55.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for fastapi_template_cli-1.2.3.tar.gz
Algorithm Hash digest
SHA256 ed0b4dd8b0b71e74aa70fadc09ea66d945892557fd782ac1fb1c176c2739c82f
MD5 b6fb8840acfdd45c265eaa1cc941e74e
BLAKE2b-256 404580f4e50c10252bd76b71cdabaf76e7d320027b85e08a1893dd0723743448

See more details on using hashes here.

File details

Details for the file fastapi_template_cli-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_template_cli-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fb5c6f640d37dbb30ba7f26d01bb017db4cbacc7bead86dcd525fc5f7c05615e
MD5 a8c4757985d7afbb7d2ff9ec373740d4
BLAKE2b-256 cbf6e39d834af53ee82e8d1137b31fbe22bfc5e4d0c8242d93b12456674cec20

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