The Hitchhiker's Guide to CLIs in Python

This article is based on my PyCon 2020 talk of the same title.


In the beginning, was the command line. Well, not quite the command line we know today.

We had typewriters. We were communicating using Morse code. One fine day, someone had an idea to connect a typewriter to …

Read

There are comments.

The Hitchhiker's Guide to CLIs in Python — Part 4: User Experience

Now that we know how to write CLIs in Python, let's talk about the CLI user experience. As mentioned earlier, we're operating in a constrained design space. In contrast to GUIs, which offer a lot of visual cues and guidance to the user.

There are some principles that can help …

Read

There are comments.

The Hitchhiker's Guide to CLIs in Python — Part 3: Writing and packaging a CLI using Click

Let's look at some common CLI use cases and how we can use click to implement them.

This time we'll use an example CLI called smol-git.


  $ smol-git --help
  Usage: smol-git [OPTIONS] COMMAND [ARGS]...

    smol-git - the stupid content tracker

  Options:
    --version  Show the version and exit.
    --help     Show this message and …
Read

There are comments.

The Hitchhiker's Guide to CLIs in Python — Part 2: Python packages for writing CLIs

Let's see how we can write a command-line interface using Python. There are several options to do this, in the standard library and on PyPI.

We'll use an example CLI called smol-pip, and see how we can implement it using these different options.


  $ smol-pip install --upgrade package_name

smol-pip has one …

Read

There are comments.

The Hitchhiker's Guide to CLIs in Python — Part 1: Anatomy of a Terminal and CLI

tty (short for teletype) is a Unix command that prints the name of the terminal connected to standard input. It is also the prefix in names for virtual terminals on Unix-based operating systems.

The fundamental type of application that runs on a terminal is the shell. The …

Read

There are comments.