Last modified: Aug 11, 2025 By Alexander Williams

Python Typer Shell Autocompletion Guide

Shell autocompletion makes CLI apps more user-friendly. Python Typer supports it for all major shells.

Why Use Autocompletion?

Autocompletion helps users discover commands and options faster. It reduces typing errors and improves UX.

Typer leverages Click's completion system. It works with bash, zsh, fish, and PowerShell.

Installation Requirements

First, ensure you have Typer installed. See our Typer installation guide.

Your CLI app must use typer.run() or the app() callback pattern.

Enabling Bash Completion

For bash, source the completion script in your .bashrc:


eval "$(_YOUR_APP_COMPLETE=bash_source your_app)"

Replace your_app with your CLI command name. The script registers completions.

Zsh Autocompletion Setup

For zsh, add this to .zshrc:


eval "$(_YOUR_APP_COMPLETE=zsh_source your_app)"

Zsh offers more advanced completion features than bash. It works similarly.

Fish Shell Configuration

Fish shell users add this to config.fish:


_YOUR_APP_COMPLETE=fish_source your_app | source

Fish provides excellent completion out of the box. The integration is seamless.

PowerShell Completion

For PowerShell, register the completer:


Register-ArgumentCompleter -Native -CommandName your_app -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
        your_app --complete $wordToComplete | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}

PowerShell requires more setup but works well with Typer.

Testing Completion

After setup, test by typing your command and pressing tab. Options should appear.

For subcommands, check our subcommands guide.

Customizing Completion

Typer uses type hints for completion. See our type hints guide.

You can customize help text that appears during completion.

Troubleshooting Tips

If completion fails, verify the eval command runs correctly. Check shell-specific logs.

Ensure your Typer app properly defines all commands and options.

Conclusion

Shell autocompletion makes Typer CLI apps more professional and user-friendly.

Setup is simple for all major shells. Users will appreciate the productivity boost.

Combine with good help text and prompts for best results.