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.6.tar.gz (51.9 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.6-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastgram_cli-0.1.6.tar.gz
  • Upload date:
  • Size: 51.9 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.6.tar.gz
Algorithm Hash digest
SHA256 ebf288d76ba9c015e74a7dce1ee6223d524ed66cd850e48b57c7838f8b8c2cd7
MD5 fb4948b82209e3081a75e44f97c78591
BLAKE2b-256 5fcdbc11349b335cef4f00c932e0cd5568f8b5a6a5fcfb4e7dac97776a77a302

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastgram_cli-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 12.2 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8573b1eb48f075b2502f8df5604baab597ad5c5da5b2f588fbb1ed61387d93cf
MD5 bc5d0737244d95cc564316b16da257ca
BLAKE2b-256 a136bf72b2e2760f598269420c2ecffa0f250a9a630f311f3cee41861397dedc

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