How to publish your Python code to PyPI

Revision as of 22:21, 22 January 2020 by (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To make your code more visible, and easy for others to install and use, you can upload it to PyPI (The Python Package Index). PyPI is a repository of software for the Python programming language. It helps people to find and install software developed and shared by the Python community.

If you have some python code that you would like to make available to others the first step is to make sure it is in a publicly viewable repository at a site like GitHub or BitBucket.

The documentation for creating a PyPI package is the ultimate authority on packaging python code for distribution via PyPI, and should be used for packages with multiple files.

If you have a single python source file (or perhaps a handful of source files) you can follow this clear and simple explanation of the minimum requirement for publishing your code on PyPI.

As an example, some python code to calculate rank histograms by CoE researcher Oliver Angélil was made into a PyPI package. The GitHub repository for rank-histogram shows the relatively simple directory structure required to create the PyPI package for rank-histogram. All that was required was to create an empty file called and a file:

from setuptools import setup

    description='Python function that takes model data, obs data, and a boolean mask to generate a rank histogram.',
    author='Oliver Marc Angelil',
    keywords='rank histogram climate ensemble Hamil'

The instructions use the python program twine which is available in the CMS conda distribution.

Other resources