After spending some time developing a cli project, you’d like to distribute it on pip (PyPI). After all, which installation procedure can beat a simple pip install? After some searching the internet you may have come across the single post on this topic I was able to find, which is from 2014 and requires you to create a bunch of folders and files to do things which are not really needed.

That blog post may also leave you wondering if there’s a better way to do things in 2019 that don’t require so much boilerplate. I thought the same, so, after reading a ton of documentation on packaging, I’ve condensed the information here so you don’t need to read it too. Here are the step-by-step instructions:

Create an account on PyPI (registration link) Create the entry point of your app (put the following code in entry.py)

def main():

print("It's alive!")

3. Install poetry

curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

source $HOME/.poetry/env

4. Set up poetry

cd myproject #Navigate to your project's directory

poetry init

5. Set up the cli command (add the following lines to pyproject.toml)

[tool.poetry.scripts]

APPLICATION-NAME = 'entry:main'

You can replace APPLICATION-NAME with whatever you want your main cli command to be.

6. Publish it! (replace with the username and password you used in step 1)

poetry publish --username PYPI_USERNAME --password PYPI_PASS --build

It’s alive! Now your users can install and use your application with just the following two lines:

$ sudo pip install PROJECT-NAME

$ APPLICATION-NAME

Where PROJECT-NAME is the name you gave to the project in step 4 (poetry init) and APPLICATION-NAME is the cli command name from step 5.