A powerful CLI tool for generating production-ready FastAPI applications with SQLAlchemy and MongoDB support
Project description
๐ 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
- ๐ Issues: GitHub Issues
- ๐ Docs: Generated README.md in your project
- ๐ฌ Discussions: GitHub Discussions
๐ค Contributing
We welcome contributions! Here's how to get started:
๐ Contribution Workflow
-
Fork & Clone
git clone https://github.com/Sohail342/fastapi-template.git cd cli-tool
-
Setup Environment
python -m venv venv source venv/bin/activate pip install -e ".[dev]"
-
Create Feature Branch
git checkout -b feature/amazing-feature
-
Make Changes
- Add new templates/backends
- Update documentation
- Add comprehensive tests
-
Test Your Changes
pytest # Test template generation fastapi-template new test-project --template fullstack --backend sqlalchemy
-
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
๐ 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
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_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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed0b4dd8b0b71e74aa70fadc09ea66d945892557fd782ac1fb1c176c2739c82f
|
|
| MD5 |
b6fb8840acfdd45c265eaa1cc941e74e
|
|
| BLAKE2b-256 |
404580f4e50c10252bd76b71cdabaf76e7d320027b85e08a1893dd0723743448
|
File details
Details for the file fastapi_template_cli-1.2.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_template_cli-1.2.3-py3-none-any.whl
- Upload date:
- Size: 72.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb5c6f640d37dbb30ba7f26d01bb017db4cbacc7bead86dcd525fc5f7c05615e
|
|
| MD5 |
a8c4757985d7afbb7d2ff9ec373740d4
|
|
| BLAKE2b-256 |
cbf6e39d834af53ee82e8d1137b31fbe22bfc5e4d0c8242d93b12456674cec20
|