Backend Development 4 min read

Using argcomplete to Add Auto-Completion for Python and pip Commands

This article explains how to install and configure the argcomplete library to provide tab‑completion for Python, pip, and other argparse‑based command‑line tools, including code snippets and tips for integrating the feature into your own Python packages.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Using argcomplete to Add Auto-Completion for Python and pip Commands

Overview: The article introduces the lack of tab completion for Python and pip commands and presents argcomplete as a solution.

Features of argcomplete: supports bash and zsh, third‑party support for tcsh and fish, can complete python and pip commands, and any argparse‑based CLI.

Enabling auto‑completion for Python and pip:

<code>pip install argcomplete</code>

Then run:

<code>activate-global-python-argcomplete</code>

Restart the shell and tab‑complete pip commands.

Enabling completion for other third‑party tools:

<code>eval "$(register-python-argcomplete <python-app-name>)"</code>

Example for pipx:

<code>eval "$(register-python-argcomplete pipx)"</code>

Adding argcomplete support to your own Python package requires adding the marker # PYTHON_ARGCOMPLETE_OK before creating the ArgumentParser, importing argcomplete, and calling argcomplete.autocomplete(parser) before parsing arguments.

After installation, the command can be completed with eval "$(register-python-argcomplete <your‑package>)" . Note that heavy operations before argcomplete.autocomplete() may cause noticeable delay.

Reference: argcomplete GitHub repository.

pythoncommand lineautocompleteargparseargcompletepip
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.