Skip to content

DS-dk/fastapi-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚡ FastAPI Boilerplate Generator

One command to scaffold a production-ready FastAPI project — just like laravel new but for Python.

python create_fastapi_app.py my-project

✨ What It Does

Tired of setting up the same folder structure, installing the same packages, and writing the same boilerplate code every time you start a new FastAPI project?

This script does everything in one shot:

  • 📁 Creates a clean, production-ready folder structure
  • 🐍 Sets up a virtual environment automatically
  • 📦 Installs all required packages
  • 🗄️ Wires up SQLAlchemy + PostgreSQL connection
  • 🔐 Sets up JWT Auth structure
  • 📋 Creates .env, .gitignore, requirements.txt, README.md
  • 🚀 Ready to run in under 60 seconds

🚀 Quick Start

1. Download the script

curl -O https://raw.githubusercontent.com/DS-dk/fastapi-boilerplate/main/create_fastapi_app.py

2. Run it

python create_fastapi_app.py my-project

3. Configure your database

cd my-project
# Edit .env and add your PostgreSQL credentials

4. Start the server

venv\Scripts\activate      # Windows
source venv/bin/activate   # Mac/Linux

uvicorn main:app --reload

5. Open API docs

http://127.0.0.1:8000/docs

That's it! 🎉


📁 Generated Project Structure

my-project/
│
├── main.py                    # Entry point — registers routes, middleware
├── requirements.txt           # All dependencies
├── .env                       # Environment variables (DB, JWT, etc.)
├── .gitignore                 # Pre-configured
│
└── app/
    ├── database.py            # SQLAlchemy engine + session + Base
    │
    ├── models/                # SQLAlchemy ORM models (like Eloquent)
    │   ├── __init__.py
    │   └── user.py            # User model (ready to use)
    │
    ├── routers/               # API route handlers (like Controllers)
    │   ├── __init__.py
    │   └── users.py           # User CRUD routes (ready to use)
    │
    ├── schemas/               # Pydantic schemas (Request validation + Response)
    │   ├── __init__.py
    │   └── user.py            # UserCreate, UserUpdate, UserResponse
    │
    ├── services/              # Business logic layer
    │   └── __init__.py
    │
    └── dependencies/          # Auth & reusable dependencies (like Middleware)
        ├── __init__.py
        └── auth.py            # JWT token verification

📦 Packages Included

Package Purpose Laravel Equivalent
fastapi Web framework Laravel
uvicorn ASGI server php artisan serve
sqlalchemy ORM Eloquent
alembic Migrations Laravel Migrations
psycopg2-binary PostgreSQL driver doctrine/dbal
pydantic Validation + Serialization FormRequest + Resources
pydantic-settings .env config Laravel Config
python-dotenv .env loader vlucas/phpdotenv
passlib[bcrypt] Password hashing Hash::make()
python-jose JWT tokens Laravel Sanctum/Passport
python-multipart Form data support

⚙️ Requirements

  • Python 3.10+
  • PostgreSQL installed and running
  • pip

🗄️ Database Setup

Edit your .env file:

DATABASE_URL=postgresql://postgres:yourpassword@localhost:5432/your_db_name
SECRET_KEY=your-super-secret-jwt-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

🤝 Contributing

PRs are welcome! If you have ideas to improve the boilerplate feel free to open an issue or submit a pull request.


📄 License

MIT — free to use in personal and commercial projects.


⭐ Support

If this saved you time, give it a star! ⭐ It helps others find it too.

About

⚡ One command to scaffold a production-ready FastAPI project with SQLAlchemy, PostgreSQL & JWT Auth — like "laravel new" for Python

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages