is it a package or a wrapper? designing, documenting, and distributing a python helper library for...

29
Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Helper Library for the Cicero API

Upload: azavea

Post on 14-May-2015

319 views

Category:

Technology


2 download

DESCRIPTION

Andrew Thompson delivered this talk at the January 2014 joint meeting of the PhillyPUG Python User's Group and the GeoPhilly GIS Meetup group. Topics covered include Rest APIs, API wrappers, Python documentation tools, and Python module packaging practices and the Python Package Index.

TRANSCRIPT

Page 1: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Is it a Package or a Wrapper?

Designing, Documenting, and Distributing a Helper Library for the Cicero API

Page 2: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

advanced

spatial analysis

on the web

• UI/UX Design

• Web/Mobile

• Data Science

• HPC

• R&D

Page 3: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API
Page 4: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API
Page 5: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

https://cicero.azavea.com/v3.1/official?last_name=Obama&valid_range=ALL&format=json&token=3oh-45c20f97769b9c0f30d3&user=851&pretty=1

Page 6: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

So that’s an API...What’s a Wrapper?

Page 7: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

So that’s an API...What’s a Wrapper?

● Reese’s cups, like APIs, are filled with awesome. Data! Peanut Butter!

● But the chocolate, like JSON and XML and HTTP, will melt all over your fingers. It’s messy.

● The wrapper keeps your hands clean so you don’t have to deal with the messy stuff.

● You just program in Python.

Page 8: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Live Demo!

Page 9: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Documentation is Important

● If you like Sphinx or reStructuredText, great.

● I don’t.○ A bit large○ A bit complicated,

build process, etc○ Markdown is more

intuitive, to me● Make docs, not

arguments

Page 10: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Pycco - lightweight, markdown docs

Page 11: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Pycco - lightweight, markdown docs

$ pip install pycco

$ pycco src/my_python_file.pypycco = mypython.py -> docs/my_python_file.html

Page 12: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Pycco - lightweight, markdown docs

Page 13: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Pycco

Page 14: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Packaging and Submitting to PyPi!

$ pip install whatever-python-library-you-want

Page 15: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

“The “Python Packaging User Guide” (PUG) aims to be the authoritative resource on how to package and install distributions in Python using current tools...”

https://python-packaging-user-guide.readthedocs.org/en/latest/index.html

Page 16: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

https://www.destroyallsoftware.com/talks/wat

Page 17: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● Python Module:○ Any single .py file.○ Or, a multi-file module, which puts many .py files in a

directory with an __init__.py, which■ Tells Python to treat that whole directory as one

module.

○ module■ __init__.py■ file1.py■ file2.py

What is a “package,” actually?

Page 18: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● Python Package:○ Often people use this word to describe a multi-file

module.○ It's also a synonym for "distribution".○ And it's also something in between the two.○ And a verb.

What is a “package,” actually?

Page 19: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● Python Distribution:○ "a versioned archive file that contains Python

packages, modules, and other resource files... The distribution file is what an end-user will download from the internet and install."

● Distributed to your users with pip and the Python Package Index.

● But you rarely come across this word.

What is a “package,” actually?

Page 20: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Why not the Python Distribution Index?

Page 21: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● Your Modules - multi-file (__init__.py) or not

My “Official” Packaging Docs

Page 22: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● Our “root” package○ (Yes, a package -

more than a module, not yet a distribution)

● docs● cicero_examples.py● CHANGES.txt● LICENSE.txt● README.rst● MANIFEST.in● setup.py

My “Official” Packaging Docs

Page 23: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● MANIFEST.in○ The distribution-

making utilities include some files by default, but not all.■ Like our docs! We

want to distribute those too!

● The manifest file describes what else to include.

My “Official” Packaging Docs

Page 24: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● You will use a utility to:○ “Package up” your

package's files○ Register your

project with PyPi○ Upload an archived

distribution file for others to download.

My Packaging Docs - setup.py

Page 25: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● setup.py provides that utility the info it needs to “package up” the distribution and submit it to PyPi.○ name, version, url,

description, classifiers, etc

My Packaging Docs - setup.py

Page 26: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

● Too many utilities!○ Distutils,

Setuptools, Distribute, Distutils2

● Different limitations!

● No guidance!● More “wat”! ● When in doubt,

use Setuptools.

More “Wat” to setup.py...

Page 27: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Finally, Ready to Upload!

$ python setup.py register -r pypi$ python setup.py sdist upload -r pypi

Page 28: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Come and get it

https://pypi.python.org/pypi/python-cicero/0.1.0$ pip install python-cicero

Page 29: Is it a Package or a Wrapper? Designing, Documenting, and Distributing a Python Helper Library for the Cicero API

Is it a Package or a Wrapper?

Both.Also a distribution. :)