fastapi-init-cli
Production-Ready FastAPI Scaffolding in Seconds
An interactive, highly configurable CLI tool to bootstrap modern, scalable FastAPI applications with SQLAlchemy 2.0, JWT Authentication, OAuth, OTP verification, and Alembic migrations.
Features • Installation • Quickstart • Architecture • API Reference • Contributing • Author
Why fastapi-init-cli?
Setting up a robust FastAPI backend for production typically takes hours: setting up async database sessions, configuring JWT authentication with refresh token lifecycle, securing password hashing with bcrypt, wiring email OTP verification, setting up Alembic migrations, and structuring files into a clean layered architecture.
fastapi-init-cli automates all of this in under 10 seconds with an interactive questionnaire, generating 100% clean, standard FastAPI code with zero vendor lock-in.
Features
- Async-First & Sync Flexibility: Full support for asynchronous SQLAlchemy 2.0 (
asyncpg,aiomysql,aiosqlite) or synchronous mode (psycopg,pymysql,sqlite). - Multi-Database Support: Out-of-the-box presets for PostgreSQL, MySQL, and SQLite.
- Modular Authentication Suite:
- JWT Tokens: Dual access and refresh token lifecycle with Bearer authentication.
- Secure Password Hashing: Native
bcrypthashing with safe password length truncation. - Google OAuth 2.0: Ready-to-use authorization code flow and user sync.
- Email Verification: 6-digit OTP dispatch and validation.
- Forgot & Reset Password: Secure OTP-based credential recovery.
- Database Migrations & Auto Table Creation:
- Pre-configured async/sync Alembic environment with model auto-discovery.
- Automatic startup table creation fallback when Alembic is disabled.
- Clean Layered Architecture:
- Separation of concerns across
core/,models/,schemas/,services/, androutes/v1/.
- Separation of concerns across
- Pydantic v2 Settings: Strongly typed environment configurations via
pydantic-settings. - Zero Runtime Overhead: The generated project has zero dependency on
fastapi-init-cli.
Installation
Install fastapi-init-cli from PyPI:
pip install fastapi-init-cli
Or run directly using pipx:
pipx run fastapi-init-cli
Quickstart
Run the interactive generator:
fastapi-init
(alias: fastapi-init-cli)
Interactive CLI Walkthrough
╭───────────────────────────────────────────────────────────────────╮
│ FastAPI Init │
│ Create a production-ready FastAPI backend in seconds. │
╰───────────────────────────────────────────────────────────────────╯
? Project / Folder name: backend
? Select database engine: PostgreSQL
? Select execution architecture: Async
? Do you want authentication? Yes
? Select authentication method: JWT + Google OAuth
? Do you want email verification? (OTP-based) Yes
? Do you want forgot-password functionality? (OTP-based) Yes
? Do you want database migrations with Alembic? Yes
Run Your New Backend
# 1. Navigate to your project
cd backend
# 2. Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Run database migrations (if Alembic is enabled)
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head
# 5. Start the development server
uvicorn app.main:app --reload
Your interactive API documentation will be immediately accessible at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Project Architecture
Every generated project follows modern FastAPI best practices and clean design patterns:
my-fastapi-backend/
├── .env.example # Example environment variables template
├── .gitignore # Production Python gitignore
├── README.md # Project documentation with endpoints guide
├── requirements.txt # Pinned dependencies for your configuration
├── alembic.ini # Alembic migration configuration (optional)
├── alembic/ # Migration scripts & environment (optional)
│ ├── env.py
│ └── script.py.mako
└── app/
├── main.py # FastAPI application factory & lifespan
├── core/
│ ├── config.py # Pydantic v2 BaseSettings
│ ├── database.py # Async/sync engine & session dependency
│ ├── dependencies.py # Auth dependencies (get_current_user)
│ └── security.py # Password hashing & JWT helpers
├── models/
│ ├── base.py # SQLAlchemy DeclarativeBase & timestamp mixins
│ ├── user.py # User ORM model
│ └── otp.py # OTP ORM model (optional)
├── schemas/
│ ├── auth.py # Token & OAuth payload schemas
│ ├── user.py # User create/read/update schemas
│ └── otp.py # OTP request/response schemas
├── services/
│ ├── auth_service.py # Login, registration, token issuance
│ ├── user_service.py # User CRUD operations
│ ├── otp_service.py # OTP generation & validation logic
│ └── email_service.py # SMTP email delivery (optional)
└── routes/
├── router.py # Master router aggregator
└── v1/
├── health.py # Service health check
├── auth.py # Authentication & OAuth routes
└── users.py # Current user profile routes
API Endpoints Reference
Depending on your selected options, your generated backend comes pre-configured with:
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/v1/health |
Service health check | No |
POST |
/api/v1/auth/register |
Register new user account | No |
POST |
/api/v1/auth/login |
Email/password login for JWT access & refresh tokens | No |
POST |
/api/v1/auth/refresh |
Exchange refresh token for new access token | No |
POST |
/api/v1/auth/verify-email |
Verify account via 6-digit OTP | No |
POST |
/api/v1/auth/resend-otp |
Resend verification OTP code | No |
POST |
/api/v1/auth/forgot-password |
Dispatch password reset OTP | No |
POST |
/api/v1/auth/reset-password |
Reset password using verified OTP | No |
GET |
/api/v1/auth/google/url |
Retrieve Google OAuth consent URL | No |
GET |
/api/v1/auth/google/callback |
Handle OAuth redirect & user synchronization | No |
GET |
/api/v1/users/me |
Fetch authenticated user profile | Yes (Bearer) |
PATCH |
/api/v1/users/me |
Update authenticated user details | Yes (Bearer) |
Development & Contributing
Contributions are always welcome! Follow these steps to set up the project locally:
-
Clone the repository:
git clone https://github.com/manthan-gori/fastapi-init-cli.git cd fastapi-init-cli
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install development dependencies:
pip install -e ".[dev]"
-
Run the test suite:
pytest
Author
Manthan Gori
- LinkedIn: linkedin.com/in/manthan-gori
- GitHub: @ManthanGori
License
This project is open-source and licensed under the MIT License.
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_init_cli-1.0.3.tar.gz.
File metadata
- Download URL: fastapi_init_cli-1.0.3.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
276a98a895677bcd4743b7e7661f88e0ff41f5c756e0b1e05f2c0c8d9eef22f4
|
|
| MD5 |
ce27a02264d6d3ca0670bb6d4f28f3e9
|
|
| BLAKE2b-256 |
c0d625822c47007cb2735dfada2f2c575e9a7dcbb97c63f9a107592081cc675b
|
File details
Details for the file fastapi_init_cli-1.0.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_init_cli-1.0.3-py3-none-any.whl
- Upload date:
- Size: 38.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
037185ea9163156e1a22a98c700b69a23dfa342e1c484805b181a73e99e1561a
|
|
| MD5 |
c7c99796483b6c4bcd7b64b526428d5d
|
|
| BLAKE2b-256 |
4c6bf7b191380680b53be71019873911c1eff62ec26463b525a296398e0f8f69
|