Monday 5:10 p.m.–5:40 p.m.
Let's read code: the requests library
Susan Tan
- Audience level:
- Intermediate
- Category:
- Best Practices & Patterns
Description
Abstract
I. This is the front-page example code that demonstrates the python-requests library. The rest of the next 30 minutes is a live walkthrough of the python-requests codebase to see how this is all implemented underneath the hood.
# r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
# r.status_code
200
# r.headers['content-type']
'application/json; charset=utf8'
# r.encoding
'utf-8'
# r.text
u'{"type":"User"...'
# r.json()
{u'private_gists': 419, u'total_private_repos': 77, …}
II. How to set up the local dev environment to quickly navigate a code base.
III. Time to open up directories and files. We’ll briefly explore aspects of the codebase and construct a working model of the different components of the python-requests library.
IV. How does the requests library make use of & access code from its upstream repos urllib3 and chardet?
VI. Summary of how "requests.get('https://api.github.com/user', auth=('user', 'pass’))” works Come learn strategies on how to read new and unfamiliar code bases. We'll read through sections of the python-requests library as a case study to trace the lifecycle of a HTTP request from beginning to end.