Each client takes a proxy differently: requests a proxies dict, httpx one proxy= on the client, aiohttp a proxy= per request or on the session. Since version 0.28.0, httpx has no proxies= argument, and aiohttp reads no proxy environment variables unless you pass trust_env=True. All three need an add-on for SOCKS.
The versions on this page are the ones PyPI served on November 25, 2026: requests 2.34.2, httpx 0.28.1 and aiohttp 3.14.5. Tutorials written before them show settings that have since changed or gone.
Where the proxy setting lives
requests takes a proxies dict keyed by scheme, on each request or once on a Session:
import requests
proxy = "http://YOUR-LOGIN:YOUR-PASSWORD@example.hproxy.com:PORT"
proxies = {"http": proxy, "https": proxy}
r = requests.get("https://example.com", proxies=proxies, timeout=15)
The host, port and login above are placeholders; the real ones come from your provider's dashboard. The requests documentation warns about the Session form: values set on session.proxies "will be overwritten by environmental proxies". Its fix is to pass proxies on every request.
httpx takes one proxy on the client or on a top-level call, and mounts for anything finer:
import httpx
proxy = "http://YOUR-LOGIN:YOUR-PASSWORD@example.hproxy.com:PORT"
with httpx.Client(proxy=proxy, timeout=15) as client:
r = client.get("https://example.com")
The proxies argument in older tutorials is gone. httpx 0.26.0, released on December 20, 2023, added proxy and deprecated proxies. Version 0.28.0 removed it on November 28, 2024, so passing it now raises a TypeError. For mounts, the docs add a gotcha: the proxy URL for the https:// key "should use the http:// scheme", because most proxies take the first connection over plain HTTP.
aiohttp takes proxy on each request, and since version 3.11.0 of November 13, 2024, also as a default on the session:
import aiohttp
proxy = "http://YOUR-LOGIN:YOUR-PASSWORD@example.hproxy.com:PORT"
async with aiohttp.ClientSession(proxy=proxy) as session:
async with session.get("https://example.com") as resp:
body = await resp.text()
A request's own proxy= wins over the session default. Version 3.14.0, released on June 1, 2026, deprecated the proxy_auth parameter, which goes away in 4.0. Keep the login in the proxy URL, or send a Proxy-Authorization header built with encode_basic_auth() through proxy_headers. The first version of this page said aiohttp had no session-level proxy, which stopped being true with 3.11.0.
We read these defaults straight from each library's source at its current release:
Environment variables
requests and httpx read HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY on their own. httpx's documentation says "Environment variables are used by default", and trust_env=False turns that off. aiohttp works the other way round. In its documentation's words, "Contrary to the requests library, it won't read environment variables by default." Pass trust_env=True to the session to opt in.
Where each client takes its proxy
| Library | Proxy setting | Reads HTTP_PROXY |
|---|---|---|
| requests | proxies dict, per request or on a Session | Yes, over Session proxies |
| httpx | proxy= or mounts=, on the client or a call | Yes, unless trust_env is off |
| aiohttp | proxy= per request or on the session | Only with trust_env on |
requests 2.34.2, httpx 0.28.1 and aiohttp 3.14.5 documentation and source, read November 25, 2026
A stray HTTP_PROXY in a shell or a container can therefore send requests and httpx traffic somewhere you did not choose. In aiohttp, the same variable does nothing until you ask for it.
SOCKS and where names are looked up
None of the three speaks SOCKS out of the box:
requests pip install "requests[socks]" socks5h:// resolves names on the proxy
httpx pip install "httpx[socks]" socks5:// and socks5h:// both resolve on the proxy
aiohttp pip install aiohttp-socks ProxyConnector, names resolved on the proxy by default
The difference that matters is where the target's name gets looked up. In requests, "Using the scheme socks5 causes the DNS resolution to happen on the client", and socks5h moves it to the proxy. httpx treats the two schemes the same: its transport builds one SOCKS proxy for both, and the handshake code sends the host name to the proxy. It has accepted socks5h only since 0.28.0. aiohttp needs the aiohttp-socks package, whose connector resolves names on the proxy by default for socks5:
import aiohttp
from aiohttp_socks import ProxyConnector
url = "socks5://YOUR-LOGIN:YOUR-PASSWORD@example.hproxy.com:PORT"
async with aiohttp.ClientSession(connector=ProxyConnector.from_url(url)) as session:
async with session.get("https://example.com") as resp:
body = await resp.text()
A name looked up on your own machine shows every target to your local resolver. That holds even when the traffic itself goes through the proxy. Our explainer on what a SOCKS5 proxy is goes deeper.
Sync, async and timeouts
requests has no async client, so a thousand URLs run one after another unless you add threads. httpx offers httpx.Client for synchronous code and httpx.AsyncClient for asyncio, and aiohttp is async only. When a job rotates a proxy pool across many requests, most of the time is spent waiting on the network. Async code lets those waits overlap. We ran no speed test, so this page ranks none of them on speed.
Default timeout and async support
| Library | Default timeout | Async |
|---|---|---|
| requests | None | No |
| httpx | 5 seconds without network activity | Yes, AsyncClient |
| aiohttp | 300 seconds per operation | Async only |
requests, httpx and aiohttp documentation, read November 25, 2026
The defaults differ more than most guides admit. The requests documentation says "requests do not time out unless a timeout value is set explicitly". httpx raises a timeout after 5 seconds of network inactivity. aiohttp gives a whole operation 300 seconds. A proxy adds one more hop that can stall, so set a timeout in all three.
Keep one client alive, too: a requests.Session, an httpx.Client or an aiohttp.ClientSession. Each holds a pool of connections, and through a proxy every new connection costs a round trip to the proxy before the request even starts.
Which to pick
- A quick script, a few requests: requests. Pass
proxiesand atimeouton each call. - A new project: httpx. The same feel as requests, a 5-second default timeout, HTTP/2 with its http2 extra, and an async client when you need one.
- A high-volume scraper rotating a pool: aiohttp or
httpx.AsyncClient, with the proxy on the session or on each request.
None of them is a niche pick. In the last 30 days PyPI served about 1.5 billion downloads of requests, and the other two and the SOCKS add-ons follow:
Every pip install counts toward these numbers, automated test runs included. Other packages pull in PySocks and socksio too, so the add-on bars are not a share of each library's users.
What no client library does for you
A library sends the request; it cannot tell whether the exit behind a proxy is alive or clean. Our free proxy checker app checks proxies from your own connection and shows the fraud score of the exit. The free proxy list API hands you the whole live pool in one call, with no key. When a hand-rolled rotation loop outgrows a list, a rotating gateway that returns a fresh residential IP per request at $0.23/GB removes the list work. The per-library guides go deeper: requests, httpx and aiohttp, and proxies for web scraping covers the request habits all three still need.
Sources
Read on November 25, 2026:
- requests: Advanced Usage (proxies, SOCKS, timeouts) and sessions.py at v2.34.2.
- httpx: Proxies, Timeouts, Environment Variables, the CHANGELOG, and _client.py and _transports/default.py at 0.28.1.
- httpcore: socks_proxy.py at 1.0.9, and socksio's utils.py, on how the host name reaches the proxy.
- aiohttp: Advanced Client Usage, Client Quickstart, CHANGES and client.py at v3.14.5.
- aiohttp-socks on PyPI, version 0.12.0.
- PyPI's JSON API for versions and release dates, and the pypistats.org API for download counts.





