package python cli tool and publish to pip
Here's how I'm using poetry
and twine
to publish python projects to pypi.org.
Start by making sure the tools we'll need are installed.
sudo apt install python3-poetry twine
Create a file called pyproject.toml
in the project root. Here's minimal template that worked for me:
[tool.poetry]
name = "<package-name>"
version = "0.1"
description = "<package-description>"
authors = ["Your Name Here <your@email.com>"]
readme = "README.md"
packages = [{include = "<python-module-name>"}]
# optional: this block tells poetry to expose one of your python functions
# as a cli tool/shell command.
[tool.poetry.scripts]
my-tool = '<python-module-name>.main:main'
[tool.poetry.dependencies]
python = "^3.7"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
You'll need to replace all the values with someting that makes senst for your project.
For publishing your package you'll have to get an account at pypi.org, setup 2-faktor authentication and register an api token.
I'm using twine to uplaod the built project to pypi.org. I guess poetry could do that too, but twine is easier:
python3 -m twine upload dist/*
twine
will promt you for a username and password. Use __token__
as username and your token as password.
username: __token__
password: pypi-HE7yZvs2GBJVHbANguWOjo5CwnTZKlVQKQUTqlswykvIJbOkOofM6pf2eGFxj64jEzFT8i986Dxa6OXtjWj6G9ZAd5J7xp4FenLWDOHepIqRvCbsWvROPL93xtGoTlGGXsmYGiHLvK0DBh0FsrE3lANngkOi5zxC8pLk1m3d47HQSXyN