Typer is a Python library for building command-line applications with standard type hints for arguments and options. It ships a typer command that can run scripts as CLIs even when they do not import Typer
Overview
Typer helps developers create command-line applications in Python by mapping function parameters and their types to CLI arguments and options. You declare parameters once with ordinary Python types such as strings, integers, booleans, files, paths, and enums, instead of learning separate CLI-specific syntax.
Applications can stay minimal—a single import and a call such as typer.run—or grow into trees of commands and subcommands with options, validation, and metadata. The library is designed for strong editor support, including completion and type checking while you write.
End users get automatic help text and shell completion when they install a package built with Typer or use the bundled typer command. Completion is supported for common shells including Bash, Zsh, Fish, and PowerShell. Errors can be shown in a formatted style through Typer’s use of Rich.
Besides embedding Typer in your code, you can use the typer program to run a Python file and treat it as a CLI, inferring options from type-annotated functions even when the script does not use Typer internally. Typer builds on ideas similar to FastAPI and has integrated Click’s codebase internally for maintainability.
Installation is done by adding the typer package to a Python project, which provides both the importable library and the typer CLI in the environment. Optional global behavior can be adjusted with environment variables such as disabling Rich output.
Key features
- CLI parameters from Python type hints
- Automatic --help for commands
- Shell completion for Bash, Zsh, Fish, PowerShell
- Command trees with subcommands and groups
- typer.run for single-function CLIs
- typer command to CLI-wrap plain scripts
- Rich-formatted CLI error output
- Support for files, paths, enums, and validation
Use cases
- Shipping Python tools with structured CLIs
- Turning annotated scripts into CLIs quickly
- Multi-command developer utilities
- Internal automation with user-friendly help
- Packages that install shell completion