protocol libraries the right way
TRANSCRIPT
![Page 1: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/1.jpg)
Building Protocol Libraries
The Right Way
![Page 2: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/2.jpg)
Hi!
![Page 3: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/3.jpg)
![Page 4: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/4.jpg)
Python HTTP• Hyper
• h2, hpack, priority, etc.
• Requests + urllib3
• PyCA (PyOpenSSL)
![Page 5: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/5.jpg)
Why All Your Libraries Are Garbage, And All But One Of Mine Are
Too
![Page 6: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/6.jpg)
Python HTTP Rocks
![Page 7: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/7.jpg)
• Requests/urllib3/HTTPie
• gunicorn
• aiohttp
• Twisted
• Tornado
![Page 8: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/8.jpg)
~0% Shared Code
![Page 9: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/9.jpg)
Code Re-Use 👍
![Page 10: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/10.jpg)
I/O
![Page 11: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/11.jpg)
• httplib: state machine and parser mixed with I/O
• aiohttp/Tornado/Twisted: state machine and parser use concurrency primitives
![Page 12: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/12.jpg)
Choice of I/O limits choice of libraries
![Page 13: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/13.jpg)
So What?
![Page 14: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/14.jpg)
Wasted Effort
![Page 15: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/15.jpg)
Reduces Experimentation
![Page 16: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/16.jpg)
Duplicate Bugs
![Page 17: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/17.jpg)
Limits Optimisation
![Page 18: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/18.jpg)
Avoiding This Problem
![Page 19: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/19.jpg)
Don’t Do I/O
![Page 20: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/20.jpg)
Alternative APIevents=handle_data(in_bytes)
out_bytes=perform_action()
![Page 21: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/21.jpg)
Not All-Purpose
![Page 22: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/22.jpg)
Build Wrappers
![Page 23: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/23.jpg)
Why Bother?
![Page 24: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/24.jpg)
=============================testsessionstarts==============================platformdarwin--Python2.7.11,pytest-2.8.5,py-1.4.31,pluggy-0.3.1rootdir:/Users/cory/Documents/Python/hyper-h2,inifile:plugins:hypothesis-1.19.0,cov-2.2.0,xdist-1.13.1gw0[513]/gw1[513]/gw2[513]/gw3[513]schedulingtestsviaLoadScheduling.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
---------------coverage:platformdarwin,python2.7.11-final-0---------------NameStmtsMissBranchBrPartCoverMissing----------------------------------------------------------------h2/__init__.py2000100%h2/connection.py4250960100%h2/errors.py17000100%h2/events.py95040100%h2/exceptions.py41000100%h2/frame_buffer.py550180100%h2/settings.py740200100%h2/stream.py2860460100%h2/utilities.py450240100%----------------------------------------------------------------TOTAL104002080100%==========================513passedin6.69seconds==========================
![Page 25: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/25.jpg)
I/O Is Application-
Specific
![Page 26: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/26.jpg)
Build A Toolbox
![Page 27: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/27.jpg)
Example• hyper-h2, a pure Python
HTTP/2 protocol stack.
• http://python-hyper.org/h2
![Page 28: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/28.jpg)
Help Us
![Page 29: Protocol libraries the right way](https://reader031.vdocument.in/reader031/viewer/2022030300/58803e371a28abfd0a8b594b/html5/thumbnails/29.jpg)
Thanks! Questions?