shtab
Automagic shell tab completion for Python CLI applications
What it is and what it does
shtab generates static shell completion scripts for Python CLI applications that use argparse. Instead of executing your application every time a user presses tab (which is slow and can have side effects), shtab analyzes your ArgumentParser once and outputs a completion script that your shell can source. It supports bash, zsh, fish, and tcsh, and handles argument choices, file/directory paths, and dynamic shell commands.
You integrate shtab into your CLI in two ways: as a library (add a few lines to your app to expose a --print-completion flag), or as a standalone CLI tool that inspects an external parser object. The package has no runtime dependencies and is actively maintained with support for Python 3.9 through 3.14.
Use it for:
- Add bash/zsh completion to an existing argparse CLI with minimal code changes
- Generate completion scripts for distribution with your application package
- Support multiple shells (bash, zsh, fish, tcsh) from a single argparse definition
- Enable dynamic completions (e.g., git branch names) without re-executing the CLI on every tab press
- Provide completion for subcommands and nested argument groups automatically
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates shell tab completion scripts for Python CLI applications built with argparse, supporting bash, zsh, fish, and tcsh without runtime overhead.
Yes. shtab is production-stable, actively maintained, has zero security vulnerabilities, and solves a real problem (shell completion) with zero runtime overhead. The copyleft license is not a barrier for using it as a library in your own CLI. Install it if you build Python command-line tools and want to offer your users fast, reliable shell completion.
Install
shtab on PyPI
pip
pip install shtabuv
uv add shtabpoetry
poetry add shtabInstalling shtab
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a release 7 days ago and 461 repository stars.
License in practice
MPL-2.0 (copyleft): you must disclose source modifications and distribute under the same license if you modify and redistribute shtab itself, but using it as a library in your own CLI does not impose restrictions on your application's license.
Quickstart
pip install shtab
import argparse
from shtab import add_argument_to_parser
parser = argparse.ArgumentParser()
add_argument_to_parser(parser)
# End-users then run: your_app --print-completion bash | source
Requires Python 3.9 or later; shell completion installation is a separate end-user step (not automatic).
Verify before relying
- Whether dynamic shell commands (e.g., git branch completion) work reliably across all supported shells
- Performance characteristics when handling very large choice sets or deeply nested subcommands
Package facts
| License | MPL-2.0 (copyleft) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 7 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,607,544/month — #2,274 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: shtab-1.10.0-py3-none-any.whl
Keywords: tab, completion, shell, bash, zsh, tcsh, fish, argparse
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
argcompleteProvides bash and zsh tab completion for Python…
permissive · top 1,000 on PyPI
click-completionAdds shell completion support (Bash, Zsh, Fish,…
permissive · top 15,000 on PyPI
auto-click-autoAutomatically enables tab shell completion for…
permissive · top 15,000 on PyPI
colcon-argcompleteAdds shell command-line completion to colcon…
permissive · top 15,000 on PyPI
cmd2cmd2 is a Python framework for building…
permissive · top 5,000 on PyPI
colcon-zshProvides Z shell (zsh) completion and…
permissive · top 15,000 on PyPI
jsonargparsejsonargparse creates command-line interfaces…
permissive · top 5,000 on PyPI
tqdm-loggableConverts tqdm progress bars to logging-friendly…
permissive · top 5,000 on PyPI
argparseProvides command-line argument parsing for…
permissive · top 1,000 on PyPI
targGenerates a command-line interface from…
permissive · top 15,000 on PyPI