An interactive CLI tool that scaffolds production-ready FastAPI projects with sensible defaults - so you can skip the boilerplate and start building right away.
Run a single command, answer a few prompts, and get a fully structured FastAPI project with:
- ποΈ Clean project layout -
api/,core/,models/,schemas/,services/ - ποΈ Database support - SQLite, MySQL, or PostgreSQL
- π§ ORM of your choice - SQLAlchemy or SQLModel
- π§ͺ Testing setup - pytest / pytest-asyncio with httpx, ready to go
- π§Ή Linter config - Black or Ruff
- π³ Docker ready - optional
Dockerfile&docker-compose.yml - βοΈ Environment config - pydantic-settings with
.envsupport - π Documentation - every folder gets a README explaining its purpose
Install fastapi-initializer as a global CLI tool β no virtual environment needed. Just install once and use the fastapi-init command from anywhere, just like uv, pip, or ruff.
Using pipx:
pipx install fastapi-initializerOr using uv:
uv tool install fastapi-initializerIf you prefer a traditional install inside a virtual environment:
pip install fastapi-initializer# Clone the repository
git clone https://github.com/DasunNethsara-04/fastapi-initializer.git
cd fastapi-initializer
# Create a virtual environment and install dependencies
uv sync
# Run the CLI directly
uv run fastapi-init my-projectfastapi-init my-projectYou'll be guided through interactive prompts:
β― FastAPI Initializer
Creating project: my-project
β― What kind of database do you want to use?
> SQLite / MySQL / PostgreSQL / None
β― Which ORM do you want to use?
> SQLAlchemy / SQLModel / None
β― What linter do you want to use?
> Ruff / Black / None
β― What testing framework do you like to use?
> PyTest / pytest-async-io / None
β― Do you want to create a Docker file for this project?
> Yes / No
β FastAPI project 'my-project' created successfully!
Then get started in seconds:
cd my-project
uv sync
uv run uvicorn app.main:app --reloadOpen http://127.0.0.1:8000/docs to see the interactive API docs.
The generated project follows a modular, production-style layout:
my-project/
βββ app/
β βββ api/
β β βββ v1/
β β β βββ users.py # User endpoints
β β βββ __init__.py # Mounts versioned routers
β β βββ deps.py # Shared dependencies (e.g. auth)
β βββ core/
β β βββ config.py # App settings via pydantic-settings
β β βββ security.py # OAuth2 / auth utilities
β βββ models/
β β βββ user.py # ORM model (SQLAlchemy / SQLModel)
β βββ schemas/
β β βββ user.py # Pydantic request / response models
β βββ services/
β β βββ user_service.py # Business logic layer
β βββ db/
β β βββ base.py # ORM Base class
β β βββ session.py # Engine & get_session() dependency
β βββ main.py # FastAPI app entry-point
βββ tests/
β βββ test_users.py # Smoke test with httpx
βββ .env # Environment variables
βββ .gitignore
βββ pyproject.toml
βββ Dockerfile # (optional)
βββ docker-compose.yml # (optional)
βββ README.md # Auto-generated project docs
Note: Folders like
models/,db/,tests/, and Docker files are only generated when you select the corresponding options.
| Folder | Purpose |
|---|---|
app/api/ |
HTTP route definitions, versioned (v1/, v2/, β¦). |
app/core/ |
App-wide settings (Settings class) and security helpers. |
app/models/ |
ORM model classes mapped to database tables. |
app/schemas/ |
Pydantic models for request validation and response serialisation. |
app/services/ |
Business-logic layer β keeps route handlers thin and testable. |
app/db/ |
Database engine, session factory, and get_session() dependency. |
tests/ |
Automated test suite using pytest + httpx. |
| Prompt | Choices | What It Generates |
|---|---|---|
| Database | SQLite, MySQL, PostgreSQL, None | app/db/session.py with connection URL and driver dependency |
| ORM | SQLAlchemy, SQLModel, None | app/models/ with model classes and app/db/base.py |
| Linter | Ruff, Black, None | Adds the linter to pyproject.toml dependencies |
| Test framework | pytest, pytest-asyncio, None | tests/ directory with async smoke test |
| Docker | Yes, No | Dockerfile, docker-compose.yml, .dockerignore |
Contributions are welcome! Here's how to get started:
# 1. Fork and clone
git clone https://github.com/DasunNethsara-04/fastapi-initializer.git
cd fastapi-initializer
# 2. Install dependencies
uv sync
# 3. Make your changes, then test
uv run fastapi-init test-project
# 4. Submit a pull requestThis project is licensed under the MIT License.
Built with:
- FastAPI - the framework this tool scaffolds
- Typer - CLI framework
- InquirerPy - interactive prompts