Skip to main content

Automagic shell tab completion for Python CLI applications

Project description

Logo

shtab

Downloads Tests Coverage PyPI conda-forge

  • What: Automatically generate shell tab completion scripts for Python CLI apps

  • Why: Speed & correctness. Alternatives like argcomplete and pyzshcomplete are slow and have side-effects

  • How: shtab processes an argparse.ArgumentParser object to generate a tab completion script for your shell

Features

  • Outputs tab completion scripts for

    • bash

    • zsh

    • tcsh

  • Supports

  • Supports arguments, options and subparsers

  • Supports choices (e.g. --say={hello,goodbye})

  • Supports file and directory path completion

  • Supports custom path completion (e.g. --file={*.txt})


Installation

Choose one of:

  • pip install shtab, or

  • conda install -c conda-forge shtab

See operating system-specific instructions in the docs.

Usage

There are two ways of using shtab:

  • CLI Usage: shtab’s own CLI interface for external applications

    • may not require any code modifications whatsoever

    • end-users execute shtab your_cli_app.your_parser_object

  • Library Usage: as a library integrated into your CLI application

    • adds a couple of lines to your application

    • argument mode: end-users execute your_cli_app --print-completion {bash,zsh,tcsh}

    • subparser mode: end-users execute your_cli_app completion {bash,zsh,tcsh}

Examples

See the docs for usage examples.

FAQs

Not working? Check out frequently asked questions.

Alternatives

  • argcomplete

    • executes the underlying script every time <TAB> is pressed (slow and has side-effects)

  • pyzshcomplete

    • executes the underlying script every time <TAB> is pressed (slow and has side-effects)

    • only provides zsh completion

  • click

    • different framework completely replacing the builtin argparse

    • solves multiple problems (rather than POSIX-style “do one thing well”)

Contributions

Please do open issues & pull requests! Some ideas:

  • support fish (#174)

  • support powershell

See CONTRIBUTING.md for more guidance.

Hits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shtab-1.7.2.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

shtab-1.7.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file shtab-1.7.2.tar.gz.

File metadata

  • Download URL: shtab-1.7.2.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for shtab-1.7.2.tar.gz
Algorithm Hash digest
SHA256 8c16673ade76a2d42417f03e57acf239bfb5968e842204c17990cae357d07d6f
MD5 71c18b84fa0b426a58946ea419b4e8d6
BLAKE2b-256 5a3e837067b970c1d2ffa936c72f384a63fdec4e186b74da781e921354a94024

See more details on using hashes here.

File details

Details for the file shtab-1.7.2-py3-none-any.whl.

File metadata

  • Download URL: shtab-1.7.2-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for shtab-1.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 858a5805f6c137bb0cda4f282d27d08fd44ca487ab4a6a36d2a400263cd0b5c1
MD5 d9874a0aed44dbb0657cfa615036bf55
BLAKE2b-256 74033271b7bb470fbab4adf5bd30b0d32143909d96f3608d815b447357f47f2b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page