CLI Development

Libraries for building command-line applications.

Python's own argparse covers basic command-line apps. Beyond that, pick Click or Typer as your Python CLI library, and style the output with Rich.

How to choose:

  • Basic command-line app with no dependencies: argparse
  • Nested commands, or subcommands loaded lazily: Click
  • Options declared once as type-hinted function parameters: Typer
  • Interactive prompts and REPLs: prompt_toolkit
  • CLI from existing code without writing a parser: Python Fire
  • Progress bar for a loop: tqdm, or alive-progress for animated bars
  • Colored text, tables, and logs: Rich, or colorama for ANSI colors on Windows
  • Full-screen app in the terminal or a browser: Textual
  • Terminal widgets on an event loop you already run: Urwid
  • Full-screen forms and ASCII animations: asciimatics

Listed in editorial order, grouped by use case. Click a column to re-sort the whole list.

Press / to search. Tap a tag to filter. Click any row for details.

Search and filter

Results

Row number Tags

General 5 projects

(Python standard library) Command-line option and argument parsing.
A package for creating beautiful command line interfaces in a composable way.
pallets/github.com/pallets/click/ / /815,819,968 downloads/month
Modern CLI framework that uses Python type hints. Built on Click.
fastapi/github.com/fastapi/typer / /242,636,570 downloads/month
A library for building powerful interactive command lines.
prompt-toolkit/github.com/prompt-toolkit/python-prompt-toolkit / /183,368,083 downloads/month
A library for creating command line interfaces from absolutely any Python object.
google/github.com/google/python-fire / /17,794,399 downloads/month

Terminal Rendering 4 projects

Python library for rich text and beautiful formatting in the terminal. Also provides a great RichHandler log handler.
Textualize/github.com/Textualize/rich / /451,076,735 downloads/month
Fast, extensible progress bar for loops and CLI.
tqdm/github.com/tqdm/tqdm / /412,344,075 downloads/month
Cross-platform colored terminal text.
tartley/github.com/tartley/colorama / /246,942,020 downloads/month
A new kind of Progress Bar, with real-time throughput, eta and very cool animations.
rsalmei/github.com/rsalmei/alive-progress / /2,558,696 downloads/month

TUI Frameworks 3 projects

A framework for building interactive user interfaces that run in the terminal and the browser.
Textualize/github.com/Textualize/textual / /55,207,626 downloads/month
A library for creating terminal GUI applications with strong support for widgets, events, rich colors, etc.
urwid/github.com/urwid/urwid / /6,651,927 downloads/month
A package to create full-screen text UIs (from interactive forms to ASCII animations).
peterbrittain/github.com/peterbrittain/asciimatics / /92,000 downloads/month

CLI Development guide

argparse is in the standard library. Python's docs call it the recommended choice when you have no more specific needs, since it gives you the most out of the box for the least code. It writes the help and usage messages and reports invalid arguments for you. For commands written as decorated functions, the same docs point to Click, and for a CLI that works with static type checking, to Typer.

Click builds a CLI from commands declared with decorators. You can nest them to any depth, and Click can load subcommands lazily at runtime. It also reads option values from environment variables and comes with helpers for ANSI colors, terminal size, and launching editors.

Typer builds a CLI from your function signatures: you declare each argument and option once, as a type-hinted function parameter. Write those hints with Annotated, which its tutorial recommends wherever possible. Its docs say you get the best results by pairing it with Rich: Typer structures the commands and options, and Rich displays the output.

prompt_toolkit is for interactive input. It can replace GNU readline or build full-screen apps. For a REPL, use a PromptSession, which keeps the history for the whole session.

Python Fire turns any Python object into a CLI: call fire.Fire() at the end of your program. Its README pitches it for developing and debugging your code, exploring existing code, and turning other people's code into a CLI. It takes each argument's type from the value you pass, not from the function signature.

tqdm adds a progress bar to any loop: wrap the iterable in tqdm(). Import it from tqdm.auto, which picks the console bar or the Jupyter widget for you. alive-progress wraps the loop in an alive_bar context manager instead, with a spinner that speeds up and slows down with your throughput.

Rich writes colored text, tables, Markdown, and syntax-highlighted code to the terminal. Start with its drop-in print, then create one Console at module level for the rest of your app. For colored logs, send the logging module's output through RichHandler.

colorama makes ANSI escape codes work on Windows and does nothing on other platforms. If that's all you need, call just_fix_windows_console().

Textual apps run in the terminal, and the textual serve command from textual-dev serves them in a browser. Build one by subclassing App, and style its widgets with CSS.

Urwid is a console widget construction set rather than a finished UI library. It runs on your choice of event loop: asyncio, or another one you already use. It's licensed under the LGPL, while Textual and asciimatics use permissive licenses.

asciimatics does full-screen text UIs, from interactive forms to ASCII animations: create a Screen, build a Scene from Effect objects, and let the Screen play it.

Ship your CLI as an installable package with a [project.scripts] entry point, not a file users run with python. Click recommends it, and shell completion in Click and Typer works through that entry point. Test your commands in-process: Click and Typer both provide a CliRunner, and Textual's run_test() drives your app as if you were using the keyboard and mouse.

Know a project that belongs here?

Tell us what it does and why it stands out.