FastAPI CLI
The command-line tool that runs, reloads, and serves your FastAPI apps
Repository Health
Technical Analysis
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 devcommand with auto-reload enabled and a localhost-only bind, tuned for the local development loop - A
fastapi runcommand 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
--verbosemode 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-cliand other Typer-based sub-apps that hook into the samefastapicommand
Common Use Cases
- Running
fastapi dev main.pywhile building an API locally, with auto-reload on file changes - Running
fastapi runas the container entrypoint in production, listening on 0.0.0.0 behind a reverse proxy - Pinning an explicit
[tool.fastapi] entrypointin pyproject.toml once a project’s app path is stable, to skip auto-discovery - Using
--verboseto 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.
Used by 2 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
/dev/push
Developer Tools · Devops
Self-hosted, open-source Vercel alternative that deploys Python, Node.js, PHP, and any Docker-compatible app from a Git push, with zero-downtime rollouts and real-time logs.