API Reference

urllib3

Powerful HTTP client for Python with connection pooling, retries, and TLS control beneath requests.

Official Documentation ↗
CompatibilityThis documentation covers version v2. Check the official docs for the latest API surface.

Installation

pippip install urllib3

Methods

Powerful HTTP client for Python with connection pooling, retries, and TLS control beneath requests.

Overview

urllib3 is the pooling, retrying HTTP layer that higher-level clients are built on. A PoolManager keeps per-host connections and hands them to request calls, while Retry and Timeout objects encode connection policy once and apply it everywhere.

Responses can buffer eagerly or stream by chunks, and TLS options, certificate authorities, and verification live on the pool. The library is thread-safe and dependency-light, which is why it anchors much of the Python HTTP ecosystem.

Core Methods

The most frequently used entry points, with signatures and runnable examples:

  • PoolManager — Thread-safe connection pool keyed by host; request borrows a pooled connection transparently.
  • request — Sends a request with inline retries and timeout; the response buffers content by default.
  • Retry — Declarative retry policy: which statuses and methods retry, and how delays grow between attempts.
  • streaming response — Disables eager buffering so the body can be read in chunks for large downloads.

Usage Notes

  • Create one PoolManager per application with tuned maxsize and timeouts; per-call pools defeat pooling.
  • Configure Retry with status_forcelist and allowed_methods rather than retrying every failure blindly.
  • Stream with preload_content=False and release connections explicitly in finally blocks.

Common Pitfalls

  • Pool maxsize below real concurrency silently discards connections and hammers TLS handshakes.
  • Retries default applies to idempotent methods only; enabling retries on POST duplicates submissions.
  • Suppressing InsecureRequestWarning instead of fixing verification ships a silent MITM window.

FAQ

How does urllib3 relate to requests?
requests builds its user-facing API on urllib3: sessions map to PoolManager, and adapters expose urllib3 retries and pools. Use urllib3 directly when you need finer pool, TLS, or retry control without another layer.
How do I disable certificate warnings?
Do not blanket-disable them. The warnings mean TLS verification is off, which removes the strongest transport protection. Fix the trust store or pass a proper ca_certs instead of suppressing the warning.
Why maxsize matters under threads?
maxsize caps pooled connections per host. Exceeding it discards connections instead of reusing them, causing churn under concurrency; size it from your real parallelism, and raise block_on_pool_limits semantics deliberately.