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 buildTo create distribution packages, navigate to the directory where your
pyproject.tomlfile is located, and run:
python3 -m buildpy -m buildThen, install Twine:
pip install twineUpload to TestPyPI by specifying the
--repositoryflag:twine upload --repository testpypi dist/*- You will be prompted to enter your username and password for TestPyPI.
- If you have a
~/.pypircfile, Twine will use the credentials from there.
You will find your package on
https://test.pypi.org/project/your_pkg_name. You can thenpip installit by adding the--index-urlflag: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 buildto ensure you have the latest version of the build tool. - Navigate to the directory where your
pyproject.tomlfile is located, and run:
python3 -m buildpy -m buildUpload 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.