Hacking Python “Requests” library.. How to start as an intermediate pythonista?

My question is conceptual, yet extremely vital for me.

I’m an intermediate Python developer. I know fair enough about it, and actually use it on a daily basis. Now, I would like to transform my capabilities from a library/API user to “designer” one.

I found that “Python Requests” library by Kenneth Reitz is an extremely good place to explore Python patterns and idioms. I need to learn to split a big problem into its essential Modules, define required classes/functions, and use them to work together.

I lack such a discipline, and I’m starving to gain this knowledge.

How should I dive into this library? It is big, with many modules (with logical names, of course), classes, and methods. I started to read the code, but I don’t know where I am and what this portion of code is designed for.

Get focused. Think of a question, then try to answer it. For example:

  • how does the library encode a dictionary into a form suitable to submit to a web server?
  • how does the library store authentication information?
  • how does the library convert a dictionary of headers into a web request?
  • how does the library implement logging?

… And so on.

You start by following common tasks; find out how a regular GET request is handled, for example, or how the .json() method works once the data has arrived.

It does help to be familiar with the subject matter modelled by a body of code. Knowing how HTTP works from a client perspective helps; if you don’t know what a 302 redirect is or how HTTP uses headers to exchange info, you will have a harder time understanding all that goes on.

Luckily the requests library does keep it’s concerns nice and separated; you don’t need to dive all the way into the urllib3 library innards for example.

0

As @Martijn Pieters has pointed out, you need to know what problems that library solves, which in practical terms means, that you have to understand the problem domain.

then you will be able to have an idea on the choices the author made, appreciate some, criticize others.

if the library is too big to get an immediate overview, I would advice to start in some place where you have an (at least approximate) idea what the code is doing, like e.g. requests/api.py and

  1. understand the objects you find there, and
  2. understand how the code you are reading modifies those objects.
  3. see if (and which) objects are created and
  4. what those objects are used for.

if you do this from several starting points, you will get an overview of the whole. it is somewhat like exploring a unknown territory.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật