Member-only story
Packaging Python Scripts into CLI Commands
Introduction
Today I want to show you how you can turn a python script from this:
$ python3 coolscript.py
To this:
$ coolscript
How It’s Done
How you are able to change a python script into a full fledged CLI command is by leveraging setup.py. I will demonstrate this by creating a program that will perform a caesar cipher on any text you provide it.
Project Structure
First we will need to create our projects directory:
$ mkdir caesar
$ cd caesar
$ mkdir caesar
$ touch setup.py
$ touch caesar/__init__.py
$ touch caesar/caesar.py
And what we should be left with is a directory structure that looks like this:
caesar/
|-- caesar
| |-- __init__.py
| `-- caesar.py
`-- setup.py
Script
Once you have the directory setup we will create the script in caesar.py. The objective of this tutorial is not to teach you how to create the script however I will add it below if you are interested.