urllib3

2.6.3 · active · verified Fri Mar 27

urllib3 is a powerful, user-friendly HTTP client library for Python providing thread-safe connection pooling, client-side TLS/SSL verification, multipart file uploads, retry helpers, redirect handling, and support for gzip, deflate, brotli, and zstd content encoding. Current stable version is 2.6.3 (released 2025). The project follows an active release cadence with security patches, minor feature releases, and occasional major versions; the 2.x line requires Python >=3.9 and OpenSSL >=1.1.1.

Warnings

Install

Imports

Quickstart

Create an explicit PoolManager and make GET/POST requests with timeout and retry logic.

import urllib3
from urllib3.util.retry import Retry
from urllib3.util.timeout import Timeout

# Explicit PoolManager — preferred over the module-level urllib3.request() in
# library code to avoid shared global state.
http = urllib3.PoolManager(
    timeout=Timeout(connect=3.0, read=10.0),
    retries=Retry(total=3, backoff_factor=0.5, status_forcelist=[500, 502, 503, 504]),
)

# Simple GET — response body is bytes; call .json() for JSON payloads
resp = http.request("GET", "https://httpbin.org/get")
print(resp.status)          # 200
print(resp.json())          # parsed JSON dict

# POST with form fields
resp = http.request("POST", "https://httpbin.org/post", fields={"key": "value"})
print(resp.status)

# POST with JSON body (sets Content-Type: application/json automatically)
resp = http.request("POST", "https://httpbin.org/post", json={"key": "value"})
print(resp.json()["json"])  # echoed back by httpbin

# Streaming a large response
resp = http.request("GET", "https://httpbin.org/stream-bytes/1024", preload_content=False)
for chunk in resp.stream(32):
    print(len(chunk), "bytes")
resp.release_conn()

view raw JSON →