Difference between revisions of "How to publish your Python code to PyPI"

 
Line 1: Line 1:
[[Category: Python]]{{Needs Update}}
+
[[Category: Python]]
  
To make your code more visible, and easy for others to install and use, you can upload it to [http://pypi.org/ | 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.
+
To make your code more visible, and easy for others to install and use, you can upload it to [http://pypi.org/ 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 [http://github.com | GitHub] or [http://bitbucket.org | BitBucket].
+
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 [http://github.com GitHub] or [http://bitbucket.org BitBucket].
  
The [https://packaging.python.org/tutorials/distributing-packages/ | documentation for creating a PyPI package] is the ultimate authority on packaging python code for distribution via PyPI. However, in many simple cases much of the information is superfluous and possibly confusing. If you have a single python source file (or perhaps a handful of source files) you can follow this [http://antrikshy.com/blog/publish-python-single-file-script-project-structure-pypi-pip-noobs-beginners | clear and simple explanation of the minimum requirement for publishing your code on PyPI].
+
The [https://packaging.python.org/tutorials/distributing-packages/ 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.  
  
As an example, some python code to calculate rank histograms by CoE researcher Oliver Angélil was made into a PyPI package. The [https://github.com/oliverangelil/rankhistogram | GitHub repository for rank-histogram] shows the relatively simple directory structure required to create the [https://pypi.python.org/pypi/rank-histogram/0.2 | PyPI package for rank-histogram]. All that was required was to create an empty file called <span style="font-family:monospace"><nowiki><u>init</u></nowiki>.py}} and a {{setup.py</span> file:
+
If you have a single python source file (or perhaps a handful of source files) you can follow this [http://antrikshy.com/blog/publish-python-single-file-script-project-structure-pypi-pip-noobs-beginners 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 [https://github.com/oliverangelil/rankhistogram GitHub repository for rank-histogram] shows the relatively simple directory structure required to create the [https://pypi.python.org/pypi/rank-histogram/0.2 PyPI package for rank-histogram]. All that was required was to create an empty file called init.py and a setup.py file:
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
from setuptools import setup
 
from setuptools import setup
Line 25: Line 27:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The [http://antrikshy.com/blog/publish-python-single-file-script-project-structure-pypi-pip-noobs-beginners | instructions] use the python program <span style="font-family:monospace">twine</span> which is available in the [https://accessdev.nci.org.au/trac/wiki/User%20Guides/conda | CMS conda distribution].
+
The [http://antrikshy.com/blog/publish-python-single-file-script-project-structure-pypi-pip-noobs-beginners instructions] use the python program twine which is available in the [[Conda|CMS conda distribution]].
  
 
===Other resources===  
 
===Other resources===  

Latest revision as of 23:21, 22 January 2020


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 init.py and a setup.py file:

from setuptools import setup

setup(
    name='rank-histogram',
    description='Python function that takes model data, obs data, and a boolean mask to generate a rank histogram.',
    version='0.2',
    url='https://github.com/oliverangelil/rankhistogram',
    install_requires=['numpy','scipy'],
    author='Oliver Marc Angelil',
    author_email='molofishy@gmail.com',
    py_modules=['ranky'],
    license='MIT',
    keywords='rank histogram climate ensemble Hamil'
)

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

Other resources