Packaging a runnable python module
Ever wondering how to distribute your awesome python CLI-tool? There are a lot of packaging options in the Python ecosystem. I spent quite a bit of time trying to figure out the easiest way to make my app installable. This article serves as a brief instruction.
The goal
- Package a runnable module
- Upload it to PyPI
- Make the module executable as shell-script
Preparing and building
I’ll use a sandbox catmeow application as an example.
- Install poetry (https://python-poetry.org/)
- `cd catmeow` # your-awesome-project-base-dir
- Add pyproject.toml file by running `poetry init` command
- Add an entry point to your module by adding the following lines to pyproject.toml:
[tool.poetry.scripts]
catmeow = “catmeow:main”
5. Build and package `python -m pep517.build .`
Uploading a package
1. Get an account on pypi.org, test.pypi.org
2. Configure credentials by adding the following file `$HOME/.pypirc`
[pypi]
username = <USER>
password = <PASS>[testpypi]
username = <USER>
password = <PASS>
3. `twine upload — repository testpypi dist/*` or if you are ready simply `twine upload dist/*`
4. Installing from testpypi `pip install — index-url https://test.pypi.org/simple/ catmeow`