Python Packaging
Rich Lewis
CMI Python Users Meeting, 16/11/2015
Packaging in General
- Packaging is important for
- code organisation
- maintainability
- distribution
Packaging in Python
- Packaging is different for each programming language
- This talk is only about Python
- Terminology doesn't translate particularly well between languages (or even between versions of languages), so be careful!
distributions
projects
packages
modules
libraries
scripts
....
It's a mess.
But it's important.
Distributions
This is what people download
These are what you find on PyPI, e.g. scikit-learn
Modules
How code is organised
import csv
csv is a module.
Packages
A 'higher level' module.
sklearn is a package.
from sklearn import preprocessing
Scripts
These are the raw source code.
In Python, every script is a module.
So how do you make these?
Scripts are easy!
Just write them.
Modules are easy!
Modules are just scripts - anything in the global scope of the script is importable.
Packages are easy!
__init__.py
Its a directory (folder for the heathens) full of Python scripts (or modules) with...
Distributions
A little more involved - see Python Foundations Packaging Guide
You need to write a setup.py file, and use setuptools.
Demo...
Create a module with imports
Create a package which allows exports
Create a distribution
Python Packaging
By Rich Lewis
Python Packaging
- 1,613