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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastgram_cli-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 2f600d3b9190c990523d9d6e668c4f9c71b02a0b32749409ff1202ba9f44876a
MD5 1c1bf005deba22a3d3d7c7ee9de73f67
BLAKE2b-256 0605dd0dcb66dc306413641e2d5d731875fc4d678705106c7affa5a7de21b24e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastgram_cli-0.1.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0a4a7cea35f8c7f0b7fdad32ab897c01a5f87c5eb67e87e616df0807548a7067
MD5 200c63ec196b8dc827650e1a5986691e
BLAKE2b-256 c6915278aa37423ca2a99e2277d4d886d5ee57e1142d545123b80ea004bff96c

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