How to create a pip package?

Last updated: Sun, 27 Nov 2016 14:01:28 GMT 0 comments

In this first post you will find quick references to the commands needed to share your package through Pypi.

Pypi, available at https://pypi.python.org, is the official repository for Python packages. Packages available on Pypi can be installed very easily using pip install <package_name>.

Registering your package and first upload

To make your Python package available on Pypi, you will need to:

  1. Create configuration files (including setup.py, setup.cfg) for your project, cf. https://packaging.python.org/distributing/#configuring-your-project for a full list.
  2. Build your package
cd <PATH_TO_PACKAGE>
python setup.py sdist
python setup.py bdist_wheel
  1. Register your project and upload to Pypi test server
python setup.py register -r https://testpypi.python.org/pypi
twine upload -r pypitest dist/*
  1. Check that the install works fine from Pypi test server
pip install -i https://testpypi.python.org/pypi <PACKAGE_NAME>
  1. Upload your package to Pypi!
twine upload -r pypi dist/*

Releasing a new version

To make a new version of your package available:

  1. Delete any previous built
cd <PATH_TO_PACKAGE>
rm -rf dist
rm -rf build
rm -rf *.egg-info
  1. Rebuild your package
python setup.py sdist
python setup.py bdist_wheel
  1. Send to Pypi test server and check the installation
twine upload -r pypitest dist/*
pip install -i https://testpypi.python.org/pypi <PACKAGE_NAME>
  1. Upload to Pypi!
twine upload -r pypi dist/*

For more information, the official documentation (with examples) is available at: https://packaging.python.org/distributing