Skip to content

Mohd-Mursaleen/SuperFastAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SuperFastAPI

npm version License: MIT

Check it out here: supfastapi on npm

Features

  • CLI Tool: Easily generate new FastAPI projects from the command line.
  • Template System: Uses Handlebars templates for flexible project generation.
  • Modular Structure: Includes pre-built modules for authentication, database integration (Supabase), configuration, and more.
  • Best Practices: Follows modern Python and FastAPI best practices for project layout and code organization.
  • Extensible: Add or customize templates to fit your needs.

✨ Features

  • πŸš€ Quick Setup: Generate a complete FastAPI project in seconds
  • πŸ—„οΈ Database Options: Choose between PostgreSQL (with Docker), Supabase, or no database
  • πŸ” Authentication: Optional Supabase authentication integration
  • 🐳 Docker Ready: Optional Docker and docker-compose configuration
  • πŸ“¦ Poetry Integration: Modern Python dependency management with Poetry
  • πŸ”§ CRUD Operations: Pre-built CRUD directory structure for PostgreSQL projects
  • πŸ§ͺ Migration Support: Alembic integration for database migrations
  • ⚑ Database Scripts: Automated db.sh script for database management
  • πŸ“ Well Documented: Generated projects include comprehensive documentation
  • 🎯 Best Practices: Follows FastAPI and Python best practices

πŸ“‹ Requirements

  • Node.js 14+ (for running the CLI)
  • Python 3.11+ (for generated projects)
  • Poetry (for Python dependency management)
  • Docker (optional, for PostgreSQL database)

πŸš€ Quick Start

Installation

Install SuperFastAPI globally via npm:

npm install -g supfastapi

Or use it directly with npx (no installation required):

npx supfastapi my-api-project

Basic Usage

Create a new FastAPI project:

superfastapi my-awesome-api

The CLI will guide you through the setup process with interactive prompts:

  1. Database Setup: Choose your database option

    • No database setup
    • Supabase (cloud database)
    • PostgreSQL (requires Docker)
  2. Authentication: Enable Supabase authentication (if using Supabase)

  3. Docker Setup: Include Docker configuration files

πŸ—„οΈ Database Options

PostgreSQL with Docker

When you select PostgreSQL, SuperFastAPI automatically includes:

  • Docker Configuration: Dockerfile, docker-compose.yml, .dockerignore
  • Database Client: SQLAlchemy setup with PostgreSQL
  • Migrations: Alembic configuration for database migrations
  • CRUD Operations: Pre-built CRUD directory structure
  • Database Management: db.sh script for common database operations

Supabase Integration

Supabase option provides:

  • Database Client: Supabase Python client setup
  • Authentication: Optional JWT-based authentication system
  • Environment Configuration: Pre-configured environment variables
  • API Routes: Ready-to-use authentication endpoints

πŸ“ Generated Project Structure

my-awesome-api/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py                 # FastAPI application entry point
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── config.py           # Application configuration
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ routes/             # API route handlers
β”‚   β”‚   β”œβ”€β”€ schemas/            # Pydantic models
β”‚   β”‚   └── middleware/         # Custom middleware
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── postgres.py         # Database connection (if PostgreSQL)
β”‚   β”œβ”€β”€ crud/                   # CRUD operations (PostgreSQL only)
β”‚   β”‚   └── __init__.py
β”‚   β”œβ”€β”€ models/                 # Database models
β”‚   β”œβ”€β”€ services/               # Business logic
β”‚   └── utils/                  # Utility functions
β”œβ”€β”€ tests/
β”‚   └── __init__.py
β”œβ”€β”€ alembic/                    # Database migrations (PostgreSQL only)
β”œβ”€β”€ docker-compose.yml          # Docker services (if Docker enabled)
β”œβ”€β”€ Dockerfile                  # Application container (if Docker enabled)
β”œβ”€β”€ db.sh                       # Database management script (PostgreSQL only)
β”œβ”€β”€ pyproject.toml              # Poetry configuration
β”œβ”€β”€ example.env                 # Environment variables template
β”œβ”€β”€ start.sh                    # Application startup script
└── README.md                   # Project documentation

🐳 Docker Usage (PostgreSQL Projects)

For projects with PostgreSQL, use these commands:

# Start PostgreSQL database only
docker-compose up -d postgres

# Install Python dependencies
poetry install

# Run database migrations
./db.sh migrate

# Start the FastAPI application
poetry run uvicorn app.main:app --reload

πŸ”§ Database Management (PostgreSQL)

The generated db.sh script provides convenient database operations:

# Check database status
./db.sh status

# Create a new migration
./db.sh create "add_users_table"

# Apply migrations
./db.sh migrate

# Show current migration
./db.sh current

# Show migration history
./db.sh history

# Open PostgreSQL shell
./db.sh shell

# Show all available commands
./db.sh help

πŸ” Environment Configuration

Generated projects include an example.env file. Copy it to .env and configure:

cp example.env .env

PostgreSQL Configuration

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/my_awesome_api

Supabase Configuration

SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key  # For auth features

πŸ“– Examples

Create a basic API project

superfastapi basic-api
# Select: No database setup
# Select: No Docker setup

Create a project with PostgreSQL and Docker

superfastapi postgres-api
# Select: PostgreSQL (requires Docker)
# Docker setup is automatically included

Create a project with Supabase authentication

superfastapi supabase-api
# Select: Supabase (cloud database)
# Select: Yes for authentication
# Select: Yes/No for Docker setup

πŸ§ͺ Development

Running Tests

npm test

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for detailed information on how to contribute to this project.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support


Made with ❀️ for the FastAPI community

About

Set Up FastAPI with few clicks

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors