Skip to content
EN
Get started

requests vs httpx vs aiohttp: Proxies Compared on the Current Versions

How requests 2.34, httpx 0.28 and aiohttp 3.14 take a proxy: where the setting goes, environment variables, SOCKS and DNS, default timeouts, and which to pick.

Billal AinaouiAugust 23, 2026Updated November 25, 20267 min read

requests vs httpx vs aiohttp: Proxies Compared on the Current Versions

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:

Our own capture, November 25, 2026, 00:12 UTC: curl 8.16.0 on our machine reading the release tags on GitHub, printed word for word.

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

LibraryProxy settingReads HTTP_PROXY
requestsproxies dict, per request or on a SessionYes, over Session proxies
httpxproxy= or mounts=, on the client or a callYes, unless trust_env is off
aiohttpproxy= per request or on the sessionOnly 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

LibraryDefault timeoutAsync
requestsNoneNo
httpx5 seconds without network activityYes, AsyncClient
aiohttp300 seconds per operationAsync 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 proxies and a timeout on 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:

PyPI downloads in the last 30 daysMillions of downloads counted by pypistats.org, known mirrors excluded, read November 25, 2026
requests
1,496 million
httpx
815 million
aiohttp
562 million
PySocksthe SOCKS add-⁠on of requests
46.5 million
socksiothe SOCKS add-⁠on of httpx
27 million
aiohttp-⁠socksthe SOCKS add-⁠on of aiohttp
5.7 million
requests is still downloaded about as often as httpx and aiohttp together.
Source: pypistats.org API, last_month for each package, read November 25, 2026; every pip download counts, test runs included · hproxy.comProxy.

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:

Frequently asked questions

Which Python HTTP client is best for proxies?

For a short synchronous script, requests. For new code that may need async or HTTP/2 later, httpx. For thousands of concurrent requests through a proxy pool, aiohttp or httpx.AsyncClient. All three take HTTP proxies, and each needs an add-on for SOCKS.

Why does my httpx code with proxies= fail?

httpx 0.28.0, released November 28, 2024, removed the proxies argument, so passing it raises a TypeError. Use proxy= with one proxy URL, or mounts= with a transport per URL pattern for anything finer.

Can I set a proxy on an aiohttp ClientSession?

Yes, since aiohttp 3.11.0 of November 13, 2024: ClientSession(proxy=...) sets a default that each request can override. Version 3.14.0 deprecated proxy_auth, so keep the login in the proxy URL or send a Proxy-Authorization header built with encode_basic_auth().

Do these libraries read the HTTP_PROXY environment variable?

requests and httpx do by default. aiohttp does only when you pass trust_env=True to the session. In requests, environment proxies also override proxies set on a Session, so pass proxies on each request if both exist.

Should I use socks5 or socks5h?

In requests, socks5 looks up the target's name on your machine and socks5h on the proxy. httpx sends the name to the proxy with either scheme, and aiohttp-socks does so by default for socks5.

Do httpx and aiohttp support SOCKS proxies?

httpx does with its socks extra, installed as httpx[socks], and a socks5:// or socks5h:// proxy URL. aiohttp has no SOCKS support of its own; the aiohttp-socks package adds a ProxyConnector. requests needs requests[socks].

Get proxies that are alive right now

Our free proxy list re-checks every exit every few minutes across 100+ countries, with a live last-checked time, so you copy IPs that worked moments ago, not a stale text dump. When the location has to survive a real check, the paid network holds up.

129M+ proxy checks run · 100+ countries · HTTP / HTTPS / SOCKS · re-checked every few minutes · no signup

HProxy.

Honest guides and comparisons on proxies, scraping and staying unblocked, from the team that runs the network.

RSS feed