Quick Guide to Packaging Python2 libraries

I’ve been learning python this summer (more on that later), and one thing that is a challenge for me was packaging my first library and shipping it to PyPi, the online repository for python modules.

First, set up your directories:

mkdir fair_flow/

mkdir fair_flow/fair_flow

cd fair_flow

touch __init__.py

sudo apt-get install python-pip python-setuptools

vi setup.py and put this in it

import setuptools

with open(“README.md”, “r”) as fh:
long_description = fh.read()

author=”Joe Fair”,
description=”Simple Workflow Library”,
“Programming Language :: Python :: 2”,
“License :: OSI Approved :: MIT License”,
“Operating System :: OS Independent”,

In the fair_flow/fair_flow/__init__.py put something simple, for testing ou tthe functionality.

name = "fair_flow"

def doit():
  return "Did It"

Install it locally

pip install .

Test it from the command line

python -c 'import fair_flow; print fair_flow.doit()'

Once you're ready, you can upload it to Pypi.  First, create your account on PyPi and install twine with 

pip install twine

Build the distribution

python setup.py sdist

And upload it

twine upload 
python -c 'import fair_flow; print fair_flow.doit()'

Then you can see it on Pypi


Thanks for hints and tips from:

  • https://python-packaging.readthedocs.io/en/latest/minimal.html
  • https://packaging.python.org/tutorials/packaging-projects/