zoochory

a python module as pypi deployment demonstration


Keywords
sample, setuptools, development
License
MIT
Install
pip install zoochory==0.0.1

Documentation

zoochory

A runnable tutorial on how to create and deploy a python module to the Python Package Index (and how to make it pip-installable).

Zoochory is a fancy name seeds piggybacking on animals, catching a ride to their new home.

Making the Package - Getting Started

virtualenv venv
source venv/bin/activate
pip install twine
pip freeze > requirements.txt
pip install -U pip setuptools
pip install wheel
pip freeze > requirements.txt
  • learn about the setup.py

    • "The primary feature of setup.py is that it contains a global setup() function"
  • learn about the other special purpose files in an installable package

  • download the example files so we can start tweaking them

wget https://raw.githubusercontent.com/pypa/sampleproject/master/setup.py
wget https://raw.githubusercontent.com/pypa/sampleproject/master/setup.cfg
wget https://raw.githubusercontent.com/pypa/sampleproject/master/README.rst
wget https://raw.githubusercontent.com/pypa/sampleproject/master/MANIFEST.in
  • As suggested in the instructions, let's create a single top-level package that has the same name as the project.
    • make it a module by adding an __init__.py file
mkdir zoochory
cd zoochory/
wget https://raw.githubusercontent.com/pypa/sampleproject/master/sample/__init__.py
# install the package locally
pip install -e .
# confirm that it worked via
pip freeze
# run an executable script if you made one
zoochory
hello-world
# uninstall
pip uninstall -y zoochory

Creating a Distribution

  • now that we've tested locally are convinced the package behaves as expected, it's time for distribution

    • should probably write some tests before distribution :-)
  • make a Source Distribution

python setup.py sdist
python setup.py bdist_wheel --universal

Uploading to PyPi

# this will prompt for your pypi.python.org username and password
twine upload dist/*

Confirm that it worked

virtualenv venv
source venv/bin/activate
pip install zoochory
hello-world
  • should result in a jolly response of:
    • Hello, from a pip installed world!

Congratulations!

  • you've created and deployed a python package to PyPi

  • it's now available publicly, far and wide, for all the world to see and use

  • pretty neat :-)