skillfed

shtab

Automagic shell tab completion for Python CLI applications

shtab v1.10.0 4.6M downloads/30d#2,274 on PyPI461
Copyleft license MPL-2.0 Active released

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 shtab

uv

uv add shtab

poetry

poetry add shtab

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleEnvironment :: MacOS XEnvironment :: Other EnvironmentIntended Audience :: DevelopersIntended Audience :: EducationIntended Audience :: End Users/DesktopIntended Audience :: Other AudienceIntended Audience :: System AdministratorsOperating System :: MacOSOperating System :: MacOS :: MacOS XOperating System :: POSIXOperating System :: POSIX :: BSDOperating System :: POSIX :: BSD :: FreeBSDOperating System :: POSIX :: LinuxOperating System :: POSIX :: SunOS/SolarisOperating System :: UnixProgramming Language :: Other Scripting EnginesProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Unix ShellTopic :: Desktop EnvironmentTopic :: Education :: Computer Aided Instruction (CAI)Topic :: Education :: TestingTopic :: Office/BusinessTopic :: Other/Nonlisted TopicTopic :: Software DevelopmentTopic :: Software Development :: Build ToolsTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Pre-processorsTopic :: Software Development :: User InterfacesTopic :: SystemTopic :: System :: Installation/SetupTopic :: System :: ShellsTopic :: System :: System ShellsTopic :: TerminalsTopic :: Utilities

Tags

shell tab completion generatorargparse bash completioncli autocomplete scriptzsh fish bash completionpython command line completionshell completion for argparse
cli-toolingshell-integration

More Software Development packages