Now that we have the local install tested, we are ready to upload the package to PyPI. But, before we do that, make sure that the metadata in setup.py (such as the name of the project, and the contact and license information) is reasonable, and that the project name is not already taken on PyPI. It is also good practice to first test upload to and download from the PyPI test instance (https://test.pypi.org) before uploading to https://pypi.org.
Before the upload, we need to create a file called .pypirc in the home directory containing (replace yourusername and yourpassword):
[distutils]account
index-servers=
pypi
pypitest
[pypi]
username = yourusername
password = yourpassword
[pypitest]
repository = https://test.pypi.org/legacy/
username = yourusername
password = yourpassword
We will proceed in two steps. First, we create the distribution locally:
$ python setup.py sdist
In the second step, we upload the generated distribution data using Twine (we install Twine into a local Pipenv):
$ pipenv run twine upload dist/* -r pypitest
Uploading distributions to https://test.pypi.org/legacy/
Uploading yourpackage-0.0.0.tar.gz
As a next step, try to install from the test instance into an isolated environment:
$ pipenv shell
$ pip install --index-url https://test.pypi.org/simple/ yourpackage
Once this is working, we are ready to upload to production PyPI:
$ pipenv run twine upload dist/* -r pypi