Is Urllib part of Python?

Feb 20, 2024 ยท 2 min read

One of the most common tasks when programming is accessing resources on the internet via URLs. As Python is a popular language for web development and automation, many wonder - is urllib built into Python for fetching URLs?

The answer is: sort of. There is a urllib module that comes with Python, but it is not technically part of the Python standard library.

The Urllib Module

Python does include a module called urllib (note all lowercase letters) that contains useful functions for opening and reading URLs. For example:

import urllib.request
with urllib.request.urlopen('http://example.com') as response:
   html = response.read()
   print(html)

So in a way, urllib is part of Python. But it's not part of the Python standard library - it's an external module that gets bundled with Python installations by default.

The distinction here is that the Python standard library contains guaranteed built-in modules like os, sys, datetime, etc. External modules like urllib, even if bundled by default, are not technically part of this standard library.

Urllib vs Requests

While urllib works for basic URL access, many Python programmers prefer to use the popular Requests module instead. Requests provides a simpler interface and more features for working with HTTP requests.

For example, to fetch a URL with Requests:

import requests

response = requests.get('http://example.com')
print(response.text)

So while urllib isn't officially part of Python, it is bundled with most Python installations and serves as a basic tool for fetching data from URLs. But for more advanced usage, a module like Requests is recommended instead.

Browse by tags:

Browse by language:

The easiest way to do Web Scraping

Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


Try ProxiesAPI for free

curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
...

X

Don't leave just yet!

Enter your email below to claim your free API key: