A historical discussion along with a survey of the current landscape of Python packaging. Also learn the basics of uploading your package to PyPi.
Presentation was given at the IndyPy user group meeting in February 2014.
1. Current State of Python
Packaging
Clayton Parker
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
2. A History Lesson
Let's start off with a bit of history.
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
3. Genesis
2000
distutils is added to the standard library in Python 1.6
2003
PyPi is up and running
2004
Setuptools and eggs are unleashed upon the world
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
4. Second Wave
2006
Jim Fulton creates Buildout
2007
Ian Bicking creates virtualenv
2008
Ian Bicking creates pip as an alternative to easy_install
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
5. The Fork
2008
Tarek Ziadé creates distribute, a fork of setuptools aiming
to keep the project alive
2008-2012
Packaging life is painful...An effort to fix packaging
(distutils2 / packaging) was abandoned.
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
6. The Present
2013
The wheel format is created out of PEP425 and PEP427
2013
pip starts using distlib, out of the ashes of distutils2 and
packaging
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
7. The Present
2013
distribute merges back into setuptools. After almost 10
years, setuptools gets to 1.0!!! And then a 2.0 not long
after.
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
8. How to install?
Easiest way to install a package is with pip:
$ pip install requests
Then to upgrade:
$ pip install --upgrade requests
Pretty simple eh?
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
10. Advanced features of pip
Can do more than just install
Ability to install from a requirements.txt file
Search PyPi
Show metadata about the current environment
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
11. How to create a package?
A basic setup.py
import os
from setuptools import setup
setup(
name='mypackage',
version='1.0',
description='Short description of the package',
long_description='reStructured text documentation',
url='http://github.com/username/mypackage',
license='BSD',
author='Author Name',
author_email='name@example.com',
py_modules=['mypackage'],
include_package_data=True,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Programming Language :: Python',
],
)
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
12. PyPi config
Setup your ~/.pypirc
[distutils]
index-servers=
pypi
[pypi]
repository = https://pypi.python.org/pypi
username = dave
password = 12345
Yes, that password is in clear text. So be careful!
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
13. PyPi Upload
Uploading a new package to PyPi:
$ python setup.py register
$ python setup.py sdist upload
$ python setup.py bdist_wheel upload
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
14. Install your package
Now you can install your package just like any other:
$ pip install mypackage
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
15. Project environments
Two common ways of handling your project
Virtualenv (Also venv in Python 3.3+)
Buildout
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
16. Virtualenv
Used to create isolated Python environments:
$ sudo pip install virtualenv
$ virtualenv myenv
$ cd myenv
Now activate and see what python is available:
$ source bin/activate
(myenv)$ which python
/Users/clayton/myenv/bin/python
Also check out virtualenvwrapper for more awesomeness!
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
17. Buildout
Used to create repeatable environments:
$
$
$
$
git clone https://example.com/git/my-buildout.git
cd my-buildout
python bootstrap.py
bin/buildout
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14
18. Links
Python Packaging User Guide
Detailed information about packaging and the tools that can be
used
Sharing Your Labor of Love
Excellent blog post detailing getting your package on PyPi
Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14