Auto-completion Using Python typer module
This will create a typer command that we be able to call in our terminal like python, git, etc.
$ pip install typer-cli
And finally, we can install completion for the current shell, and it won’t be required to install it again in the future.
$ typer –install-completion
Now, we are ready to use the typer feature autocompletion. We just need to use typer command instead of the python command and also add run command after the filename in the CLI.
Here’s how we can run the script in typer CLI.
typer [filename.py] run [function]
The function is auto-completed when we press the Tab key.
Note: To make the auto-completion work, there should not be any call to app(). If you do not remove this line, it’ll give RecursionError.
Python Typer Module
Typer is a library for building powerful command-line interface applications in the easiest way. It is easier to read and the simplest way to create a command line application rather than using the standard Python library argparse, which is complicated to use. It is based on Python 3.6+ type hints and is built on top of Click(Typer inherits most of the features and benefits of Click), which is a Python package to build a command-line interface. The module also provides automatic help and automatic completion for all the shells. Furthermore, it is short to write and easy to use.