Release your Python package
After bundling your source code into a package, you can publish it to PyPI. This will allow others to easily install your package using pip
.
Testing packaging on TestPyPI before publishing to PyPI
By testing your package on TestPyPI before publishing it to PyPI, you can identify and address any issues with your package metadata, dependencies, or distribution files before making your package publicly available.
You’ll need to create an account for TestPyPI. The next step is to create distribution packages for your package. These packages are archives that can be uploaded to TestPyPI/PyPI and installed using pip
. Then you can use Twine to upload your package to TestPyPI.
Register on TestPyPI.
Check if PyPA build is installed:
pip install --upgrade build
To create distribution packages, navigate to the directory where your
pyproject.toml
file is located, and run:
python3 -m build
py -m build
Then, install Twine:
pip install twine
Upload to TestPyPI by specifying the
--repository
flag:twine upload --repository testpypi dist/*
- You will be prompted to enter your username and password for TestPyPI.
- If you have a
~/.pypirc
file, Twine will use the credentials from there.
You will find your package on
https://test.pypi.org/project/your_pkg_name
. You can thenpip install
it by adding the--index-url
flag:pip install --index-url https://test.pypi.org/simple/your_pkg_name
Publishing to PyPI
Once you have tested your package on TestPyPI and ensured everything works as expected, you can publish it to the official PyPI repository. It will be accessible to anyone in the Python community, allowing them to install your package using a simple pip install your_pkg_name
command.
You’ll also need an account for PyPI. TestPyPI and PyPI use separate databases so you need to register on both sites. However, the workflow is about the same:
- Register on PyPI.
- Run
pip install --upgrade build
to ensure you have the latest version of the build tool. - Navigate to the directory where your
pyproject.toml
file is located, and run:
python3 -m build
py -m build
Upload your package to PyPI:
twine upload dist/*
- Input your credentials associated with the account you registered on the official PyPI platform.
Your package is live on PyPI!
You can now install it by simply
pip install your_pkg_name
.