The Hitchhiker's Guide to CLIs in Python
Tags: python, cli, guide
Published: 2020-05-08 08:27:26

This article is based on my [PyCon 2020 talk](https://www.youtube.com/watch?v=Hn-syMunNy8) of the same title. Originally published at [vinayak.io](https://vinayak.io) on May 4, 2020.

---

[In the beginning, was the command line](http://cristal.inria.fr/~weis/info/commandline.html). 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 an existing network of communication wires. And the teletypewriter was born!

<p align="center">
  <img style="width: 70%; height: auto;" src="https://vinayak.io/files/tty-ww2.jpg" />
</p>

Image: Teletype teleprinters in use during World War II, Source: [Wikipedia](https://en.wikipedia.org/wiki/Teleprinter?ref=hackernoon.com#/media/File:WACsOperateTeletype.jpg)

Teletypes removed the need for a human to know Morse code, which improved message typing speed and delivery time. In this [1932 video](https://www.youtube.com/watch?v=n-eFFd5BmpU), the narrator describes how a teletype takes only a matter of seconds to deliver a message from London to Edinburgh. A stark contrast to the earlier ETA of one week — the time taken by a mail coach to undertake the same 600 km journey.

<p align="center">
  <img style="width: 70%; height: auto;" src="https://vinayak.io/files/mainframes.jpg" />
</p>

Image: Assembly of IBM 1401 computers, Source: [Computer History Museum](https://www.computerhistory.org/revolution/mainframe-computers/7/166/663?ref=hackernoon.com)

Meanwhile, computers were becoming powerful enough to interact with users in real-time. Another fine day, someone had an idea to repurpose a teletype, connect it to a modem, and use it as a remote interface to early computers. This was the origin of the command-line interface!

Among these teletypes were the [Friden Flexowriter](https://en.wikipedia.org/wiki/Friden_Flexowriter) and the [Teletype Model 33](https://en.wikipedia.org/wiki/Teletype_Model_33). Users typed commands after a prompt character was printed on paper. After they were satisfied with the input, they would press Enter which would then send the command to the computer. And finally the output from the computer would be printed on paper again.

<p align="center">
  <img style="width: 70%; height: auto;" src="https://vinayak.io/files/vt100.jpg" />
</p>

Image: The VT100, Source: [Wikipedia](https://en.wikipedia.org/wiki/VT100?ref=hackernoon.com#/media/File:DEC_VT100_terminal.jpg)

Teletypes were continued to be used as terminals to computers, until video displays came into the picture during the late 1970s. Video terminals quickly became popular input-output devices for computers after the manufacturers moved to a set of [common standards](https://en.wikipedia.org/wiki/Computer_terminal#Early_VDUs).

<p align="center">
  <img style="width: 70%; height: auto;" src="https://vinayak.io/files/tty-modern.png" />
</p>

Today, physical teletypes and video terminals are obsolete. We instead have terminal emulators, which are [software simulations of the real thing](http://www.linusakesson.net/programming/tty/). But, have modern terminal emulators borrowed any features from the OG metal beasts?

## The Guide

**[Part 1 — Anatomy of a Terminal and CLI](https://vinayak.io/2020/05/04/the-hitchhikers-guide-to-clis-in-python-part-1-anatomy-of-a-terminal-and-cli)**<br>
The jargon file. Learn how terminals and CLIs work.

**[Part 2 — Python packages for writing CLIs](https://vinayak.io/2020/05/04/the-hitchhikers-guide-to-clis-in-python-part-2-python-packages-for-writing-clis)**<br>
Look at packages that can be used to write CLIs, which are available in the Python standard library and on PyPI.

**[Part 3 — Writing and packaging a CLI using Click](https://vinayak.io/2020/05/04/the-hitchhikers-guide-to-clis-in-python-part-3-writing-and-packaging-a-cli-using-click)**<br>
Explore various CLI use cases and see how Click can be used to implement a clone of git, with some commonly used git subcommands.

**[Part 4 — User Experience](https://vinayak.io/2020/05/04/the-hitchhikers-guide-to-clis-in-python-part-4-user-experience)**<br>
Look at some principles that can create a nice CLI user experience.

<h2 id="closing-thoughts">Closing Thoughts</h2>

I hope that you got a lot of touchpoints to the CLI ecosystem which you can now explore further, an understanding of how terminals and CLIs work and how to write CLIs in Python!

Stay safe and be well.