FastAPI CLI

The command-line tool that runs, reloads, and serves your FastAPI apps

Tool
PyPI
v0.0.32
639stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
87/100Excellent
Development Activity96
Maintenance100
Community64
Maturity48
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture82
Code Quality88
Innovation78
Learning Curve90

FastAPI CLI is the official command-line program bundled with FastAPI’s standard install, giving you a single fastapi command to run your applications in both development and production. It auto-detects your FastAPI app object by scanning conventional entrypoints (main.py, app.py, api.py and their app/ variants), figures out the correct import path, and hands off to Uvicorn so you never have to hand-write an uvicorn.run() invocation yourself.

Under fastapi dev it enables auto-reload and binds to localhost for a fast local feedback loop, while fastapi run disables reload and binds to 0.0.0.0 for container-friendly production serving. A --verbose flag surfaces exactly how the app was discovered and imported, and pyproject.toml can pin an explicit [tool.fastapi] entrypoint once auto-discovery is no longer wanted.

What You Get

  • A fastapi dev command with auto-reload enabled and a localhost-only bind, tuned for the local development loop
  • A fastapi run command with reload disabled and a 0.0.0.0 bind, tuned for containerized production deployment
  • Automatic discovery of your FastAPI app object across conventional file layouts (main.py, app.py, api.py, and app/ package variants)
  • A --verbose mode that prints exactly which file, module, and variable were resolved, plus how to pin that choice in pyproject.toml
  • Optional integration points for fastapi-cloud-cli and other Typer-based sub-apps that hook into the same fastapi command

Common Use Cases

  • Running fastapi dev main.py while building an API locally, with auto-reload on file changes
  • Running fastapi run as the container entrypoint in production, listening on 0.0.0.0 behind a reverse proxy
  • Pinning an explicit [tool.fastapi] entrypoint in pyproject.toml once a project’s app path is stable, to skip auto-discovery
  • Using --verbose to debug why the wrong app object or module was picked up in a monorepo or multi-package layout

Under The Hood

Architecture - The CLI is a thin Typer application (src/fastapi_cli/cli.py) exposing dev and run commands that both funnel into a shared _run() helper: it resolves an entrypoint via FastAPIConfig.resolve() (config.py), falls back to discover.py’s auto-discovery of conventional file/module layouts, then hands the resolved module:app import string straight to uvicorn.run(), so FastAPI CLI itself never touches request handling — it only decides what to import and how to launch it. Tech Stack - Built on Typer for the command surface, Rich and rich-toolkit for the formatted terminal output (trees, syntax highlighting, colored panels), Pydantic for validating the optional [tool.fastapi] pyproject.toml config, and Uvicorn (via an optional-but-expected dependency) as the actual ASGI server; fastapi-cloud-cli and fastapi-new are soft-imported and grafted on as extra Typer sub-apps when installed. Code Quality - The package is fully typed (py.typed marker, mypy strict mode, ty checks in CI) and carries 55 test files covering CLI invocation, discovery across single-file/package/default-directory layouts, and pyproject.toml parsing, with coverage tracked via a badge and coverage[toml]. API Design - The public surface is exactly two commands (fastapi dev, fastapi run) with mirrored flags, sensible host/port defaults that differ by mode (127.0.0.1+reload for dev, 0.0.0.0+no-reload for run), and a --verbose escape hatch that explains its own auto-discovery decisions instead of failing silently — very low boilerplate to get a FastAPI app running.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search