This is the setup procedure for publishing a package to PyPI using poetry.
See @ shinichi-takii's article for PyPI itself and PyPI account registration.
If it is not already installed, install poetry and keyring. The keyring is used to store your PyPI account information (it's okay if you don't have one, but it's better to install it. For macOS, it will use your keychain).
See @ canonrock16's article on installing poetry.
See @ hidelafoglia's article on installing keyring.
Register the URL of Test PyPI with the name ** testpypi **.
poetry config repositories.testpypi https://test.pypi.org/legacy/
The non-Test PyPI is built into the poetry itself so you don't have to do anything.
Access PyPI and Test PyPI and issue an API Token.
Click Add API token.
Enter any Token name and select Scope. Click Add token.
An API Token will be issued, so copy it.
Register the PyPI API Token.
poetry config pypi-token.pypi "PyPI API Token"
Register the API Token for Test PyPI.
poetry config pypi-token.testpypi "Test PyPI API Token"
If you want to create a package from now on, execute the command poetry new pathname
, and the following files will be created under the directory specified by the path.
├── README.rst
├── Path name
│ └── __init__.py
├── pyproject.toml
└── tests
├── __init__.py
└── test_Path name.py
Open the pyproject.toml
file and add the following items to the[tool.poetry]
section (you don't have to, but it's better):
Make sure to match the file name of the readme.
[tool.poetry]
description = "Short description"
license = "License name"
homepage = "Homepage URL"
repository = "Source repository URL"
readme = "README.md"
The setup.py
file is automatically generated at build time, so you don't have to prepare it yourself.
If you execute the following command, the source tarball and whl file will be created under the dist directory.
poetry build
To upload to Test PyPI, specify the registered repository name.
poetry publish -r testpypi
If you're uploading to a non-Test PyPI, you don't need to specify anything.
poetry publish
By using poetry, even a Python beginner could easily create and publish a package.
Recommended Posts