[Python] PyPI package publishing procedure using poetry

Introduction

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.

Preparation

Install poetry and keyring

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.

Registering the test repository

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.

Issuance of API Token

Access PyPI and Test PyPI and issue an API Token.

image.png

Click Add API token.

image.png

Enter any Token name and select Scope. Click Add token.

image.png

An API Token will be issued, so copy it.

API Token registration

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"

Creating a package

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.

Build package

If you execute the following command, the source tarball and whl file will be created under the dist directory.

poetry build

Upload package

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

in conclusion

By using poetry, even a Python beginner could easily create and publish a package.

Recommended Posts

[Python] PyPI package publishing procedure using poetry
[Python] Get Python package information with PyPI API
Procedure to use TeamGant's WEB API (using python)
Python development flow using Poetry, Git and Docker
Start using Python
A procedure manual for quickly publishing a C ++ Python library using pybind11 on Github.
Scraping using Python
How to make a Python package using VS Code
Speech transcription procedure using Python and Google Cloud Speech API
python package dependencies and virtual environment management tool Poetry
Operate Redmine using Python Redmine
Fibonacci sequence using Python
Data analysis using Python 0
Python package development notes
Data cleaning using Python
Python ipaddress package notes
Using Python #external packages
WiringPi-SPI communication using Python
Age calculation using python
Search Twitter using Python
Python package manager comparison
Name identification using python
Notes using Python subprocesses
Try using Tweepy [Python2.7]
python> Link> PyUserInput package |
Package python runtime and pypi library with chef / omnibus and Docker
Python environment construction procedure memo using Docker on Windows10 Home