Packaging a runnable python module

Sergey Royz
1 min readDec 6, 2020

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.

  1. Install poetry (https://python-poetry.org/)
  2. `cd catmeow` # your-awesome-project-base-dir
  3. Add pyproject.toml file by running `poetry init` command
  4. 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`

--

--

Sergey Royz

Co-founder and CTO of a crypto startup. A full-stack software engineer with a passion for creating innovative tech solutions that make a difference.