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.7.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.7-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastgram_cli-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 01c507fe54417caa4d97b7d19ce5e8829dbd3af4617cd04a106831422fae715d
MD5 48d3648d082c249ea4b64b293d0fcd72
BLAKE2b-256 efa0fac2bb46e246830c82733c4c905b427297e108b2e2c6df2b53c741e992f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastgram_cli-0.1.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 439a4fa23a841937a9307dc41fd10d713334167d750d152753b9118f7b573876
MD5 888f67d03c9bfd93503ebfc4b9e2f492
BLAKE2b-256 73fb948656fe41dee45a28e018185108fca3889408c7c0b08a145f45eac658e9

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