What are the differences between the urllib, urllib2, urllib3 and requests module?

This is my understanding of what the relations are between the various “urllibs”:

In the Python 2 standard library there exist two HTTP libraries side-by-side. Despite the similar name, they are unrelated: they have a different design and a different implementation.

  • urllib was the original Python HTTP client, added to the standard library in Python 1.2. Earlier documentation for urllib can be found in Python 1.4.

  • urllib2 was a more capable HTTP client, added in Python 1.6, intended as a replacement for urllib:

    urllib2 – new and improved but incompatible version of urllib (still experimental).

    Earlier documentation for urllib2 can be found in Python 2.1.

The Python 3 standard library has a new urllib which is a merged/refactored/rewritten version of the older modules.

urllib3 is a third-party package (i.e., not in CPython’s standard library). Despite the name, it is unrelated to the standard library packages, and there is no intention to include it in the standard library in the future.

Finally, requests internally uses urllib3, but it aims for an easier-to-use API.

Leave a Comment