A powerful, production-ready FastAPI boilerplate with automatic CRUD API generation using SQLModel and async PostgreSQL.
- β‘ Automatic CRUD API Generation - Generate complete REST APIs with a single command
- ποΈ Async PostgreSQL Support - Built with SQLModel and asyncpg for high performance
- ποΈ Soft Delete - Built-in soft delete with restore functionality
- π‘οΈ Type Safety - Full Python type hints and Pydantic validation
- ποΈ Clean Architecture - Proper separation of concerns with repository pattern
- π§ CLI Tool - Scaffold new apps and models quickly
- π Auto Documentation - Automatic OpenAPI/Swagger documentation
- π Production Ready - Error handling, logging, and health checks
- Python 3.8+
- PostgreSQL 12+
- Clone and install:
git clone <your-repo-url>
cd my-api
pip install poetry
poetry install --no-root- Setup database:
createdb mydatabase
cp .env.example .env
# Edit .env with your database credentials- Create your first API:
python cli.py full blog Post -f "title:str,content:str,author:str"- Run the server:
poetry run fastapi dev src/main.py --host 0.0.0.0 Visit http://localhost:8000/docs to see your auto-generated API documentation!
# Create a blog app with Post model
python cli.py full blog Post -f "title:str,content:str,author:str"
# Add more models to existing app
python cli.py model blog Comment -f "content:str,post_id:int,author:str"
python cli.py model blog Category -f "name:str,description:str"# Create app structure first
python cli.py app_create blog
# Then add models
python cli.py model blog Post -f "title:str,content:str"python cli.py list_appsEach model automatically gets these REST endpoints:
| Method | Endpoint | Description | Example |
|---|---|---|---|
GET |
/{models} |
List items (paginated) | GET /api/v1/posts |
GET |
/{models}/{id} |
Get item by ID | GET /api/v1/posts/1 |
POST |
/{models} |
Create new item | POST /api/v1/posts |
PUT |
/{models}/{id} |
Update item | PUT /api/v1/posts/1 |
DELETE |
/{models}/{id} |
Soft delete | DELETE /api/v1/posts/1 |
PATCH |
/{models}/{id}/restore |
Restore item | PATCH /api/v1/posts/1/restore |
DELETE |
/{models}/{id}/force |
Permanent delete | DELETE /api/v1/posts/1/force |
curl -X POST "http://localhost:8000/api/v1/posts" \
-H "Content-Type: application/json" \
-d '{
"title": "My First Post",
"content": "This is the content",
"author": "John Doe"
}'curl "http://localhost:8000/api/v1/posts?page=1&per_page=10"curl -X PUT "http://localhost:8000/api/v1/posts/1" \
-H "Content-Type: application/json" \
-d '{"title": "Updated Title"}'src/
βββ core/ # Framework core
β βββ bases/ # Base classes (Repository, Service, Router)
β βββ database.py # DB configuration & models
β βββ exceptions.py # Custom exceptions
β βββ cli.py # Code generator CLI
βββ apps/ # Your business apps
βββ blog/
βββ models/ # SQLModel classes
βββ repositories/ # Data access layer
βββ services/ # Business logic
βββ routers/ # API routes
βββ schemas/ # Pydantic schemas
DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/mydatabase
SECRET_KEY=your-super-secret-key
ENVIRONMENT=development
DEBUG=Truefrom src.core.database import BaseModel
from sqlmodel import Field
class Post(BaseModel, table=True):
__tablename__ = "blog_posts"
title: str = Field()
content: str = Field()
author: str = Field()class PostService(BaseService[Post]):
async def _validate_create(self, create_data: Dict[str, Any]) -> None:
if len(create_data.get('title', '')) < 5:
raise ValidationException("Title must be at least 5 characters")# Development with auto-reload
python main.py
# Or using uvicorn
uvicorn main:app --reload --host 0.0.0.0 --port 8000- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
# Update environment
ENVIRONMENT=production
DEBUG=False
# Run with production settings
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]Table doesn't exist error:
- Ensure models are imported in
database.py - Restart server after creating new models
Database connection issues:
- Verify PostgreSQL is running
- Check DATABASE_URL in .env file
Import errors:
- Check Python path and module structure
- Verify all
__init__.pyfiles exist
We welcome contributions! Please feel free to submit pull requests or open issues for bugs and feature requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
β Star this repo if you find it helpful!