Skip to content

Uploading Releases to PyPi

Michael Joyce edited this page Jul 26, 2023 · 6 revisions

Push a Release to PyPi

Before packaging a new release, make sure the package is prepared for a new release following the release process guidelines.

Package the Project

Checkout the appropriate release tag:

git checkout tags/<tag_name>

Make sure wheel is installed and create a wheel by running:

poetry build

The distribution file should appear in dist/

Publish the Package to PyPi

Now that the distribution file is built, the package can be published. Make sure twine is installed to upload the distribution. Optionally, create a ~/.pypirc to store repository and credential information:

[distutils]
index-servers =
  pypi
  pypitest
  
[pypi]
repository=https://upload.pypi.org/legacy/
username=my username
password=my password

[pypitest]
repository=https://test.pypi.org/legacy/
username=my username
password=my password

This stores credentials as plain text, so it may be wise to change the permissions on this file:

chmod 600 ~/.pypirc

See more about ~/.pypirc in the documentation.

Test with PyPi Test

It is wise to test the distribution first by pushing it to the PyPi test repository, specified as [pypitest] in ~/.pypirc or at the url https://test.pypi.org/legacy/.

To use the credentials stored in ~/.pypirc, specify the name of the repository using the --repository flag.

twine upload --repository pypitest dist/*

Without a ~/.pypirc, upload the distribution to the target repository using the --repository-url flag:

twine upload --repository-url https://test.pypi.org/legacy/ dist/*

Enter the username and password when prompted.

Once the upload is complete, the package can be viewed at https://test.pypi.org/project/ait-core/.

Upload to PyPi

Now that we've test-published the package to PyPi Test, we can publish it to the real PyPi repository.

We can use the tag name from ~/.pypirc:

twine upload --repository pypi dist/*

Or use the full url:

twine upload --repository-url https://upload.pypi.org/legacy/ dist/*