Post

How to create a Python CLI that's globally available in your system in 5 easy steps. 1. Install uv 2. Init project with `uv init --app --package mycli` 3. Write code 4. Install with `uv tool install . -e` 5. Use `mycli` anywhere in your computer

14 reposts76 likes

If you write the code in the right function in the right file, you don't even need to edit the pyproject.toml. (You need to have a function `main` importable from `mycli`, if I'm not mistaken. To specify a different entry point you'd have to modify the file `pyproject.toml`.)

The reason I added -e is so that changes in the code you make to mycli are immediately visible by your system. If you want to version your CLI properly, I'd omit the `-e` from the installation command. Disclaimer: I'm not a packaging expert. Nor a uv expert.

Super nice trick. I've never used it, I just have scripts with inline deps and a uv shebang in a dir added to my PATH. But the advantage of your method is that nobody has to know about the PATH and it works cross platform.