Python CLI Utilities

Python CLI Utilities

Up until recently, I haven't done a lot with python since college. I wrote the occasional script here and there. Anytime that I did, I ended up using the standard python argparse libraries and just ran it with python However I always wanted to write a real CLI utility. I put it off because of how much work it would be. Then I wrote one and found out its only a few extra lines of code.

Making a utility

Organize the code

Just make a folder called whatever you want the CLI utility to be called and put the main source code in there in a file called The main code should be in a function called def cli().

Then in the folder above that, create with a very simple setup:

 from setuptools import setup, find_packages

That's it.

Consuming it

After its written, anyone could download it from source and use pip install --editable . and get it working. However how could I make it so it was even simpler? The pypi website was always foreboding to me since it looks like a hacker board from 1996. Once again, I was overthinking it. Just make an account, create a package submission on their site, then run a few commands:

  • Register the repo: python register -r pypi
  • Upload the code: python sdist upload -r pypi

That's it.

So in summary, I've been running away from signing up on a website, making one extra .py file, and running like 2 extra CLI commands.

And because I now know that, now I've written several over the last few weeks.