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.
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 certificatecerts/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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34f91c3ae58305e8b7b596e7cd80ae3be2629e82974a1d5545681f22ed249ce4
|
|
| MD5 |
d9304659a101878c92cd772d07217368
|
|
| BLAKE2b-256 |
a20c529b3b8a56b68993895906f02e88546bf30193dd1559362ff20c57869ea9
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
133d072e0c57949424d539cd8b3a388e6c8a7022c9bbac56728c19abd76847f0
|
|
| MD5 |
076d1932073e15c8558a62624ef990b3
|
|
| BLAKE2b-256 |
2c7002127b7555f4f085c3feabc4a50f59015bc6fc309a7da95f408155c4ed1e
|