+ All Categories
Home > Internet > How to Write a Popular Python Library by Accident

How to Write a Popular Python Library by Accident

Date post: 19-Jan-2017
Category:
Upload: daniel-greenfeld
View: 778 times
Download: 1 times
Share this document with a friend
114
How to Write a Popular Python Library by Accident Daniel Roy Greenfeld Audrey Roy Greenfeld Thursday Keynote Speech June 23, 2016
Transcript
Page 1: How to Write a Popular Python Library by Accident

How to Write a Popular Python Library by Accident

Daniel Roy Greenfeld Audrey Roy Greenfeld

Thursday Keynote Speech June 23, 2016

Page 2: How to Write a Popular Python Library by Accident

How to Write a Popular Python Library by Accident

Daniel Roy Greenfeld Audrey Roy Greenfeld

Thursday Keynote Speech June 23, 2016

Page 3: How to Write a Popular Python Library by Accident

@audreyr @pydanny

About Us

Daniel Roy Greenfeld Audrey Roy Greenfeld

Met at PyCon US 2010 Married December 2013

Open Source Developers

Engineer & Principal, Cartwheel Web Engineer & Principal, Cartwheel Web

Page 4: How to Write a Popular Python Library by Accident

@audreyr @pydanny

You Might Know Our Open Source Work

Responsibility

Page 5: How to Write a Popular Python Library by Accident

@audreyr @pydanny

So Much Open Source Work?! Why?

PortfolioSolves problems

CommunityResponsibility

Page 6: How to Write a Popular Python Library by Accident

@audreyr @pydanny

So Much Open Source Work?! Why?

Community

Biggest Reason:

It’s Gratifying

Page 7: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Python Package IndexFind Open Source Python packages

Page 8: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Python Package IndexWho is familiar with PyPI?

Page 9: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Python Package IndexWho here has released a package on PyPI?

Raise your hand.

Page 10: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Everyone here should release a package on PyPI.

Python Package Index

Page 11: How to Write a Popular Python Library by Accident

@audreyr @pydanny

package

I don’t know how to do it

I’m not creative enough

I don’t have enough experience

I’m not a visionaryNonsense!

But Isn’t Releasing Packages Hard?

Page 12: How to Write a Popular Python Library by Accident

@audreyr @pydanny

The Big Secret About Open Source

Packages

Page 13: How to Write a Popular Python Library by Accident

@audreyr @pydanny

The Big Secret

Creators of Packages aren’t

special visionaries

are

Page 14: How to Write a Popular Python Library by Accident

@audreyr @pydanny

They are coders like you and me

Page 15: How to Write a Popular Python Library by Accident

@audreyr @pydanny

One difference…

Page 16: How to Write a Popular Python Library by Accident

@audreyr @pydanny

They release open source

packages

Page 17: How to Write a Popular Python Library by Accident

@audreyr @pydanny

A Single Function

The Big Secret

Installable Package

Page 18: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Secret Package Recipe #1

Step 1: Pick a FunctionStep 2: Get the BoilerplateStep 3: Add Function to

Boilerplate

Page 19: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Secret Package Recipe #2

Step 1: Pick a ClassStep 2: Get the BoilerplateStep 3: Add Class to

Boilerplate

Page 20: How to Write a Popular Python Library by Accident

@audreyr @pydanny

CookiecutterPackagesmakes packaging trivial

BoilerplateTool for generating boilerplate for Python packages (and other projects)

Page 21: How to Write a Popular Python Library by Accident

@audreyr @pydanny

DEMO

Page 22: How to Write a Popular Python Library by Accident

@audreyr @pydanny

CookiecutterPackagesmakes packaging trivial

BoilerplateTool for generating boilerplate for Python packages (and other projects)

Page 23: How to Write a Popular Python Library by Accident

@audreyr @pydanny

packagesSmall But Useful Packages

binaryornot

cached-property

Page 24: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Packages

Complex Project

Installable Package

Page 25: How to Write a Popular Python Library by Accident

@audreyr @pydanny

sComplex Project

Page 26: How to Write a Popular Python Library by Accident

@audreyr @pydanny

projectoften grow from simple projects

sComplex Project

Page 27: How to Write a Popular Python Library by Accident

@audreyr @pydanny

What project should you build?

Page 28: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Build what you need!

😀

Page 29: How to Write a Popular Python Library by Accident

@audreyr @pydanny

😁😄😅 😆😉😊😋😺

Community might follow

😀

Page 30: How to Write a Popular Python Library by Accident

@audreyr @pydanny

😀

CommunityDon’t worry if the

community follows

😮

😋

😁😄

😅😺

😉😊

Page 31: How to Write a Popular Python Library by Accident

@audreyr @pydanny

😮

Focus on your needs

😀

Focus on your story

Page 32: How to Write a Popular Python Library by Accident

@audreyr @pydanny

storyStory of

cached-property

Page 33: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Story of cached-property

4 Class Package

Caches object properties

Page 34: How to Write a Popular Python Library by Accident

@audreyr @pydanny

class cached_property(object): """ A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property. Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76 """ # noqa

def __init__(self, func): self.__doc__ = getattr(func, '__doc__') self.func = func

def __get__(self, obj, cls): if obj is None: return self value = obj.__dict__[self.func.__name__] = self.func(obj) return value

Started at 9 lines of codeNow has 131 lines of code

Story of cached-property

Page 35: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Story of cached-property

bugs.python.org/issue21145

Page 36: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Story of cached-property

You never know who will use your library :)

Page 37: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Don’t be Super

Ambitious

Page 38: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Identify small problems

Don’t be

Ambitious

Page 39: How to Write a Popular Python Library by Accident

@audreyr @pydanny

and fix them

small

Page 40: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stories

Django Packages

Requests

Cookiecutter

Matplotlib

django-uni-form django-crispy-forms/

…and fix them

Page 41: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Story

django-uni-form

django-crispy-forms

Page 42: How to Write a Popular Python Library by Accident

@audreyr @pydanny

django-uni-form

2009

Page 43: How to Write a Popular Python Library by Accident

@audreyr @pydanny

django-uni-form

• Danny started his first professional Django project.

• US Government projects must be Section 508.

2009

• Django is not Section 508!

Page 44: How to Write a Popular Python Library by Accident

@audreyr @pydanny

What is Section 508?

•Color-blind •Blind

Page 45: How to Write a Popular Python Library by Accident

@audreyr @pydanny

“Forms must be defined not in tables, but in divs”

Rule

Page 46: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Uh-oh…

• Project had 80 forms.

• How do we convert 80 forms from tables to divs…

• …without going crazy?

Page 47: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Reuse the Code!# uni_form/templatetags/uni_form_tags.pyfrom django import templateregister = template.Library()from django.utils.safestring import mark_safe  @register.filterdef as_uni_form(form): text = '' for field in form: text = """ <div class="ctrlHolder"> %s %s : %s </div> """ % (field.errors, field.label_tag(), field) return mark_safe(text)https://github.com/pydanny/django-uni-form/commit/e0f02cb9120f794a17bec297f0b1778f066a9168

Page 48: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Package the Code!

django-uni-form

Page 49: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Growing the django-uni-form

API

Page 50: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Growing the API

Added entire HTML form

generation via Python

Page 51: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Growing the API

Added HTML form button

controls

Page 52: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Growing the API

Fancier HTML Control and Layout

Widgets

Project grew and grew…

Page 53: How to Write a Popular Python Library by Accident

@audreyr @pydanny

ProjectSometimes you leave a project

django-uni-form

Page 54: How to Write a Popular Python Library by Accident

@audreyr @pydanny

django-uni-form

django-crispy-forms2390 Github ⭐!

django-crispy-forms

Page 55: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stories

django-uni-form / django-crispy-forms

Requests

Cookiecutter

Matplotlib

Django Packages

Page 56: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Django PackagesDjango Dash 2010

djangopackages.com

Page 57: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Django PackagesDjango Dash 2010

djangopackages.com

Page 58: How to Write a Popular Python Library by Accident

@audreyr @pydanny

“Automatic Birthday Greetings for Facebook!”

Django Dash 2010

We were too lazy to learn the Facebook API

Idea #1:

Page 59: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Django Dash 2010

Idea #2:“What about making comparison grids for

for Django packages?”

Page 60: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Small Scopehttps://code.djangoproject.com/wiki/CMSAppsComparison

Django Dash 2010

Page 61: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stretch Goals

• Anyone could Add Packages

• Anyone can Add Packages to Grids

• Fetch data from GitHub and PyPI

Django Dash 2010

Page 62: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Django Dash 2010:)

Thoughts

Built over a weekend contest

Django Packages was a need

Focus on your needs.

Page 63: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stories

django-uni-form / django-crispy-forms

Django Packages

Cookiecutter

Matplotlib

requests

Page 64: How to Write a Popular Python Library by Accident

@audreyr @pydanny

urllib + urllib2 doesn’t meet your needs?

Use requests

Page 65: How to Write a Popular Python Library by Accident

@audreyr @pydanny

requestsWinter 2011

Kenneth’s problem: urllib and urllib2 are

hard to use

Page 66: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Winter 2011

requests

changelog

Page 67: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stories

django-uni-form / django-crispy-forms

Django Packages

requests

Cookiecutter

Matplotlib

Page 68: How to Write a Popular Python Library by Accident

@audreyr @pydanny

CookiecutterSummer 2013

Audrey’s experiment: Create as many new

packages as I can, just for fun

Page 69: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Summer 2013

Cookiecutter

packages

Got tired quickly of copy/pasting boilerplate

from package to package

Page 70: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Great contributing instructions

tests!

Python module

Travis-CI

PyPI boilerplate

More PyPI boilerplate

boilerplate

Cookiecutter

Page 71: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Cookiecutter

I had just d a static site

generator called “complexity”

create

Page 72: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Cookiecutter

What if I used similar concepts to create a

project template renderer?

Page 73: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Cookiecutter was born!

Page 74: How to Write a Popular Python Library by Accident

@audreyr @pydanny

After first release, the pull requests began

Cookiecutter

Page 75: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Cookiecutter

Page 76: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Cookiecutter

Then Danny

blogged about it.

http://bit.ly/25W87lM

Page 77: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Cookiecutter

Danny needed an image for his blog post.

Page 78: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Danny needed an image for his blog post.

Page 79: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Page 80: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Page 81: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Great contributing instructions

tests

Python module

Travis-CI

PyPI boilerplate

More PyPI boilerplate

Page 82: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Now anyone can create and submit packages

to PyPI in minutes!

Page 83: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Are there too many PyPI packages?

“I hate how there are too many packages. I can’t find what I need.”

— grumpy coder— beginner

Page 84: How to Write a Popular Python Library by Accident

@audreyr @pydanny

The grumpy coder:Doesn’t know how to search intelligently

“Grr, there are too many websites. I miss the old WWW before Google.”

Page 85: How to Write a Popular Python Library by Accident

@audreyr @pydanny

The grumpy coder:

Doesn’t read Python blogs or books

Page 86: How to Write a Popular Python Library by Accident

@audreyr @pydanny

The grumpy coder:

Doesn’t attend Python user groups to help find

great tools

Page 87: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Always Remember:

Doesn’t attend Python

Page 88: How to Write a Popular Python Library by Accident

@audreyr @pydanny

The more packages that exist, the better

Always Remember:

Page 89: How to Write a Popular Python Library by Accident

@audreyr @pydanny

More packages means a diversity of selection

Page 90: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Different viewpoints on the same problem

Different viewpointspackages

Page 91: How to Write a Popular Python Library by Accident

@audreyr @pydanny

• Flask

• Pyramid

• Tornado

• Bottle

• Web2py

• cherrypy

• web.py

• Falcon

• Bluebreem

• Turbogears

• Google App Engine

• Or write your own!

Django doesn’t meet your needs? Use another web framework

Different viewpoints

Page 92: How to Write a Popular Python Library by Accident

@audreyr @pydanny

youDjango doesn’t meet your needs? Use another web framework

• Flask

• Pyramid

• Tornado

• Bottle

• Web2py

• cherrypy

• web.py

• Falcon

• Bluebreem

• Turbogears

• Google App Engine

• Or write your own!

(Bold items were written as Django alternatives)

Page 93: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Python shell not quite what you want?

Started as a 259-line experiment by Fernando Perez

Now 180K+ LOC

Page 94: How to Write a Popular Python Library by Accident

@audreyr @pydanny

you

More Packages More Options

More Toolshttp://pixabay.com/en/carrots-variety-vegetables-76653/

your contribution

Page 95: How to Write a Popular Python Library by Accident

@audreyr @pydanny

More is Good

Than to be limited by options that don’t meet your needs

Better to write a new library

Page 96: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stories

django-uni-form / django-crispy-forms

Django Packages

Requests

Cookiecutter

Matplotlib

Page 97: How to Write a Popular Python Library by Accident

@audreyr @pydanny

MatplotlibThe story of

Page 98: How to Write a Popular Python Library by Accident

@audreyr @pydanny

John Hunter (1968-2012)

• Matplotlib was his brainchild

• His work benefits our species

• http://numfocus.org/news/2012/08/28/johnhunter/

Page 99: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Matplotlib

• Created in 2002 to solve a major problem:

• Epilepsy causes seizures

• Some children don’t respond to the medications. They need brain surgery

by John Hunter

Story told to us by Fernando Perez of IPython/Jupyter, John’s close friend and collaborator.

Page 100: How to Write a Popular Python Library by Accident

@audreyr @pydanny

brainsurgery

Treatment: Open Brain, Analyze Seizure Data, Surgery

Problem: Expensive, Limiting Analysis Tool

Matplotlib

Page 101: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Problem: Expensive, Limiting Analysis Tool

Matplotlib

Page 102: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Solution Part 1

Matplotlib

Page 103: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Solution Part 2

Matplotlib

Page 104: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Solution Part 3

Matplotlib

Page 105: How to Write a Popular Python Library by Accident

@audreyr @pydanny

3-d inferred location of seizure focus, together with active electrodes.

Matplotlib

Page 106: How to Write a Popular Python Library by Accident

@audreyr @pydanny

MatplotlibThe birth of

• John Hunter originally offered his plotting code to Fernando Perez as a patch (contribution) to IPython

• Fernando Perez liked it but had to focus on finishing his grad thesis

• John turned that code into matplotlib

Page 107: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Stories

django-uni-form / django-crispy-forms

Django Packages

Requests

Cookiecutter

Matplotlib

Page 108: How to Write a Popular Python Library by Accident

@audreyr @pydanny

You never know what project will grow from a

small piece of FOSS code

Page 109: How to Write a Popular Python Library by Accident

@audreyr @pydanny

project

• They are minor fixes or enhancements

• They fit the project’s needs/goals

Contribute changes to existing projects if:

Page 110: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Start a new project if:

• No other project does what you need

• You’ve tried the other options already

• You feel that it will give you:

• Less resistance

• More freedom to do what you want

Page 111: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Anyone can…

Create and release a package

on PyPI

All you have

JUST DO IT!

Page 112: How to Write a Popular Python Library by Accident

@audreyr @pydanny

All you have to do is

JUST DO IT!

Page 113: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Daniel Roy Greenfeld Audrey Roy GreenfeldEngineer & Principal, Cartwheel Web Engineer & Principal, Cartwheel Web

Met at PyCon US 2010 Married December 2013

Open Source Developers

Page 114: How to Write a Popular Python Library by Accident

@audreyr @pydanny

Daniel Roy Greenfeld Audrey Roy GreenfeldEngineer & Principal, Cartwheel Web Engineer & Principal, Cartwheel Web


Recommended