Packaging Python Scripts into CLI Commands

Introduction

$ python3 coolscript.py
$ coolscript

How It’s Done

Project Structure

$ mkdir caesar 
$ cd caesar
$ mkdir caesar
$ touch setup.py
$ touch caesar/__init__.py
$ touch caesar/caesar.py
caesar/ 
|-- caesar
| |-- __init__.py
| `-- caesar.py
`-- setup.py

Script

Setup File

Entry Points

entry_points={
'console_scripts': [
'caesar = caesar.caesar:main'
]
},
$ sudo python3 setup.py install
$ caesar "Test Message" 
Whvw Phvvdjh
$ caesar "Whvw Phvvdjh" --decrypt
Test Message

Conclusion

Cybersecurity Analyst and Finance Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store