Argcomplete adds shell tab completion to Python CLI programs built with argparse. It supports bash and zsh with optional global activation across installed scripts.
Overview
Argcomplete bridges Python's argparse module and shell completion frameworks so users can tab-complete options, subcommands, and argument values at the terminal. Programs call argcomplete.autocomplete() on the parser before parse_args(), and mark scripts with PYTHONARGCOMPLETEOK when using global completion discovery.
Completion can be static from argparse choices or dynamic through custom completer callables that receive prefix text, the active action, parser state, and partially parsed arguments. Zsh can show help strings alongside suggestions when completers return description mappings.
Registration per application uses register-python-argcomplete, while activate-global-python-argcomplete enables discovery for any executable exposing the marker in its first kilobyte. Global mode relies on bash features introduced in 4.2; macOS users on older bash builds may need a newer bash or zsh.
The library requires Python 3.10 or newer. Maintainers document bash and zsh on Linux and macOS as supported shells, with contributed notes for fish, PowerShell, and other environments in a separate contrib area rather than core support.
Key features
- argparse parser integration hook
- Custom dynamic completer functions
- Global PYTHONARGCOMPLETEOK discovery
- Per-app shell registration helper
- Zsh completion descriptions
- Readline-style completer support
- Choice-based static completions
- Custom completion validators
Use cases
- CLI tools with many subcommands
- Network-backed completion values
- Developer ergonomics for Python scripts
- Operations tools with long option lists