Skip to main content

CLI tool for FastAPI - generate SSL certificates and more

Project description

fastgram

A modern CLI tool for FastAPI developers - initialize projects with middleware, manage settings, and generate SSL certificates.

Python Version License PyPI Version

Features

  • ๐Ÿš€ Initialize FastAPI project structure with Django-like folder layout
  • ๐Ÿ” Generate self-signed SSL certificates
  • ๐Ÿ“ฆ Pre-configured middleware (CORS, Request ID, Logging, Rate Limit)
  • โš™๏ธ Centralized settings (server, middleware, rate limits)
  • ๐Ÿ’… Beautiful output with Rich library
  • โšก Fast and easy to use
  • ๐Ÿ“ฆ Ready for PyPI publication

Installation

From GitHub

pip install git+https://github.com/ndugram/fastgram-cli.git

From Source

git clone https://github.com/ndugram/fastgram-cli.git
cd fastgram
pip install -e .

Quick Start

# Initialize a new project
fastgram init myproject

# Enter project directory
cd myproject

# Start development server
python manage.py runserver

# Open in browser
# http://127.0.0.1:8000
# API docs: http://127.0.0.1:8000/docs

Initialize Project

fastgram init [name]

Creates a new FastAPI project structure with pre-configured middleware:

project_name/
โ”œโ”€โ”€ api/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ core/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ database/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ schema/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ service/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ views/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ middleware/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cors.py
โ”‚   โ”œโ”€โ”€ logging.py
โ”‚   โ”œโ”€โ”€ rate_limit.py
โ”‚   โ”œโ”€โ”€ request_id.py
โ”‚   โ””โ”€โ”€ loader.py
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ manage.py
โ””โ”€โ”€ settings.py

Default project name: backend

Middleware

Generated projects include these middleware by default:

Middleware Description
RateLimitMiddleware Rate limiting (default: 5 requests/second)
LoggingMiddleware Logs incoming HTTP requests
CORSMiddleware Cross-Origin Resource Sharing (permissive)
RequestIDMiddleware Adds unique request ID to each request

Configure Middleware

Edit settings.py to modify middleware:

MIDDLEWARE = [
    "middleware.rate_limit.RateLimitMiddleware",
    "middleware.logging.LoggingMiddleware",
    "middleware.cors.CORSMiddleware",
    "middleware.request_id.RequestIDMiddleware",
]

Rate Limit Settings

Configure rate limiting in settings.py:

RATE_LIMIT_LIMIT = "5/second"  # Format: "<count>/<second|minute>"

Settings

All configuration is centralized in settings.py:

SECRET_KEY = "generated_secret_key_here"

# Database settings
DB_URL = "sqlite+aiosqlite:///./db.sqlite3"

# Server settings
HOST = "127.0.0.1"
PORT = 8000
RELOAD = True

# Rate limit settings
RATE_LIMIT_LIMIT = "5/second"

# Middleware registration
MIDDLEWARE = [
    "middleware.rate_limit.RateLimitMiddleware",
    "middleware.logging.LoggingMiddleware",
    "middleware.cors.CORSMiddleware",
    "middleware.request_id.RequestIDMiddleware",
]

Generate SSL Certificates

Creates SSL certificates in certs/ directory:

  • certs/cert.pem - SSL certificate
  • certs/key.pem - Private key

Commands

Command Description
init [name] Initialize FastAPI project structure
ssl Generate self-signed SSL certificates
help Show available commands

manage.py Commands

After initializing a project, use manage.py for development tasks:

cd myproject

Run Development Server

python manage.py runserver                    # Default: 127.0.0.1:8000
python manage.py runserver --host 0.0.0.0     # Bind to all interfaces
python manage.py runserver --port 8080        # Custom port
python manage.py runserver --noreload         # Disable auto-reload

Database Migration

python manage.py migrate                      # Create database tables

Show Help

python manage.py help

Project Structure

Generated projects follow a clean architecture:

myproject/
โ”œโ”€โ”€ api/          # API route handlers
โ”œโ”€โ”€ core/         # Core application settings
โ”œโ”€โ”€ database/     # Database models and connections
โ”œโ”€โ”€ middleware/   # Custom middleware (CORS, Logging, Rate Limit, etc.)
โ”œโ”€โ”€ schema/       # Pydantic schemas
โ”œโ”€โ”€ service/      # Business logic
โ”œโ”€โ”€ views/        # View controllers
โ”œโ”€โ”€ main.py       # FastAPI application entry point
โ”œโ”€โ”€ manage.py     # Django-like management script
โ””โ”€โ”€ settings.py   # Centralized configuration

Requirements

  • Python 3.10+
  • OpenSSL (for SSL certificate generation)

Contributing

Contributions are welcome! Please read our Contributing Guide.

Security

For security issues, please read our Security Policy.

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastgram_cli-0.1.9.tar.gz (53.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastgram_cli-0.1.9-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file fastgram_cli-0.1.9.tar.gz.

File metadata

  • Download URL: fastgram_cli-0.1.9.tar.gz
  • Upload date:
  • Size: 53.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for fastgram_cli-0.1.9.tar.gz
Algorithm Hash digest
SHA256 34f91c3ae58305e8b7b596e7cd80ae3be2629e82974a1d5545681f22ed249ce4
MD5 d9304659a101878c92cd772d07217368
BLAKE2b-256 a20c529b3b8a56b68993895906f02e88546bf30193dd1559362ff20c57869ea9

See more details on using hashes here.

File details

Details for the file fastgram_cli-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: fastgram_cli-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for fastgram_cli-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 133d072e0c57949424d539cd8b3a388e6c8a7022c9bbac56728c19abd76847f0
MD5 076d1932073e15c8558a62624ef990b3
BLAKE2b-256 2c7002127b7555f4f085c3feabc4a50f59015bc6fc309a7da95f408155c4ed1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page