Skip to main content

A universal CLI launcher for FastAPI applications with daemon mode, logging, and rich UI

Project description

FastAPI Launcher ๐Ÿš€

A universal CLI launcher for FastAPI applications with daemon mode, logging, and rich UI.

ไธ€ไธช้€š็”จ็š„ FastAPI ๆœๅŠกๅฏๅŠจๅ™จ๏ผŒๆ”ฏๆŒๅฎˆๆŠค่ฟ›็จ‹ๆจกๅผใ€ๆ—ฅๅฟ—็ฎก็†ๅ’Œ็พŽๅŒ–็ปˆ็ซฏ่พ“ๅ‡บใ€‚

Features | ็‰นๆ€ง

  • ๐Ÿ”ฅ Hot Reload - Development mode with auto-reload | ๅผ€ๅ‘ๆจกๅผ่‡ชๅŠจ้‡่ฝฝ
  • ๐Ÿš€ Production Ready - Multi-worker support with uvicorn | ็”Ÿไบงๆจกๅผๅคš worker ๆ”ฏๆŒ
  • ๐Ÿ‘ป Daemon Mode - Background process support (Unix) | ๅฎˆๆŠค่ฟ›็จ‹ๆจกๅผ
  • ๐Ÿ“Š Rich UI - Beautiful terminal output with Rich | ็พŽๅŒ–็ปˆ็ซฏ่พ“ๅ‡บ
  • โš™๏ธ Flexible Config - CLI, ENV, .env, pyproject.toml | ็ตๆดป็š„้…็ฝฎ็ณป็ปŸ
  • ๐Ÿฅ Health Check - Built-in health monitoring | ๅ†…็ฝฎๅฅๅบทๆฃ€ๆŸฅ
  • ๐Ÿ“ Access Logs - Request logging with slow request detection | ่ฏทๆฑ‚ๆ—ฅๅฟ—ๅ’Œๆ…ข่ฏทๆฑ‚ๆฃ€ๆต‹
  • ๐Ÿ” Auto Discovery - Automatically find your FastAPI app | ่‡ชๅŠจๅ‘็Žฐ App

Installation | ๅฎ‰่ฃ…

# Using pip
pip install fastapi-launcher

# Using uv
uv add fastapi-launcher

Quick Start | ๅฟซ้€Ÿๅผ€ๅง‹

# Development mode with hot reload
fa dev

# Production mode
fa start --workers 4

# Daemon mode (Unix only)
fa start --daemon

# Check status
fa status

# Stop server
fa stop

# View logs
fa logs --follow

# Health check
fa health

# Show configuration
fa config

# Check dependencies
fa check

Configuration | ้…็ฝฎ

Configuration Priority | ้…็ฝฎไผ˜ๅ…ˆ็บง

  1. CLI arguments (highest) | CLI ๅ‚ๆ•ฐ๏ผˆๆœ€้ซ˜๏ผ‰
  2. Environment variables (FA_ prefix) | ็Žฏๅขƒๅ˜้‡
  3. .env file | .env ๆ–‡ไปถ
  4. pyproject.toml | pyproject.toml
  5. Default values (lowest) | ้ป˜่ฎคๅ€ผ๏ผˆๆœ€ไฝŽ๏ผ‰

pyproject.toml

[tool.fastapi-launcher]
app = "main:app"
host = "0.0.0.0"
port = 8000
log_level = "info"

# Development mode overrides
[tool.fastapi-launcher.dev]
reload = true
log_level = "debug"

# Production mode overrides
[tool.fastapi-launcher.prod]
workers = 4
log_format = "json"

Environment Variables | ็Žฏๅขƒๅ˜้‡

FA_APP=main:app
FA_HOST=0.0.0.0
FA_PORT=8000
FA_RELOAD=true
FA_WORKERS=4
FA_LOG_LEVEL=info
FA_LOG_FORMAT=pretty  # or json
FA_DAEMON=false

Commands | ๅ‘ฝไปค

fa dev

Start development server with hot reload.

fa dev                          # Auto-discover app
fa dev --app main:app           # Specify app
fa dev --port 9000              # Custom port
fa dev --no-reload              # Disable reload
fa dev --reload-dirs src,lib    # Watch specific dirs

fa start

Start production server.

fa start                        # Default 4 workers
fa start --workers 8            # 8 workers
fa start --daemon               # Background mode
fa start --host 0.0.0.0         # Bind to all interfaces

fa stop

Stop running server.

fa stop                         # Graceful shutdown
fa stop --force                 # Force kill
fa stop --timeout 30            # Custom timeout

fa restart

Restart server.

fa restart                      # Stop + Start
fa restart --timeout 10         # Custom stop timeout

fa status

Show server status.

fa status
# Output:
# โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
# โ”‚      Server Status          โ”‚
# โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
# โ”‚ Status   โ”‚ โ— Running        โ”‚
# โ”‚ PID      โ”‚ 12345            โ”‚
# โ”‚ URL      โ”‚ http://...:8000  โ”‚
# โ”‚ Uptime   โ”‚ 2h 30m 15s       โ”‚
# โ”‚ Memory   โ”‚ 128.5 MB         โ”‚
# โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

fa logs

View server logs.

fa logs                         # Last 100 lines
fa logs -n 50                   # Last 50 lines
fa logs --follow                # Tail mode
fa logs --type access           # Access logs
fa logs --type error            # Error logs

fa health

Check server health.

fa health                       # Default endpoint
fa health --path /ready         # Custom endpoint
fa health --timeout 10          # Custom timeout

fa config

Show current configuration.

fa config
# Output shows merged config from all sources

fa check

Check dependencies and configuration.

fa check
# โœ“ FastAPI is installed
# โœ“ uvicorn is installed
# โœ“ Configuration is valid
# โœ“ App path is valid: main:app

fa clean

Clean runtime files.

fa clean                        # Interactive
fa clean --yes                  # Skip confirmation
fa clean --logs                 # Only log files

Project Structure | ้กน็›ฎ็ป“ๆž„

After running fa start, a runtime directory is created:

your-project/
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ main.py
โ””โ”€โ”€ runtime/
    โ”œโ”€โ”€ fa.pid          # PID file
    โ””โ”€โ”€ logs/
        โ”œโ”€โ”€ fa.log      # Application log
        โ”œโ”€โ”€ access.log  # Request log
        โ””โ”€โ”€ error.log   # Error log

App Auto-Discovery | ่‡ชๅŠจๅ‘็Žฐ

FastAPI Launcher will look for your app in these locations:

  1. main.py โ†’ main:app
  2. app.py โ†’ app:app
  3. api.py โ†’ api:app
  4. server.py โ†’ server:app
  5. src/main.py โ†’ src.main:app

Supported variable names: app, application, api

License | ่ฎธๅฏ่ฏ

MIT License

Contributing | ่ดก็Œฎ

Contributions are welcome! Please feel free to submit issues and pull requests.

ๆฌข่ฟŽ่ดก็Œฎ๏ผ่ฏท้šๆ—ถๆไบค issues ๅ’Œ pull requestsใ€‚

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

fastapi_launcher-0.1.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

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

fastapi_launcher-0.1.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_launcher-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_launcher-0.1.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fastapi_launcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 00d3a4669b0d52d3daa6575e2936eddb78292dcae828ea9c22ca4f31500dbe02
MD5 79ec6649a57767731307388f655dcfad
BLAKE2b-256 eb35dd4ad218130b83fba80f567ab6a1366b3a9dfd99357610047e8213a7c2ad

See more details on using hashes here.

File details

Details for the file fastapi_launcher-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_launcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9599925fc1595193b039c1183876b57ec22ca7a209e6c6f0ab468d3aa87fdbf
MD5 bb3029c39706d4202d4398652d091718
BLAKE2b-256 2f5864de2c068a04344199765609952377690ad82420661c2b40ed51c9295354

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