Quickstart: Packaging in Python

Creating your first Python package can be intimidating, but it doesn’t have to be! Below are the basic instructions, with up-to-date links to examples for each step, and links to best practices. Steps 5 and 6 show options to make your package pip installable, whether your package is public or private.

  1. Add a setup.py script in the project root.
    • Official pypa example setup.py: https://github.com/pypa/sampleproject/blob/master/setup.py
    • More thorough explanations: https://packaging.python.org/tutorials/distributing-packages/
    • Note: To include tests, add the following:
  2. Optional: Add setup.cfg file.
  3. Optional: Package using python setup.py sdist 
    • This will create a dist folder containing all of your distributions
  4. Push ( git push ) to remote (public or private) git repository
  5. Install from remote repository
  6. Optional: Upload to PyPi
    1. Register your package: python setup.py register
    2. Upload your package:  python setup.py sdist upload
    3. What to do if you get a message like:  error: Upload failed (403): Invalid or non-existent authentication information. : Create a  ~/.pypirc  file with the following contents:
       

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.