Skip to content

HTTPX

HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2.

Making Async requests

async with httpx.AsyncClient() as client:
    r = await client.get('https://www.example.com/')

Enabling HTTP/2

If you're issuing highly concurrent requests you might want to consider trying out our HTTP/2 support. You can do so by first making sure to install the optional HTTP/2 dependencies...

pip install httpx[http2]

And then instantiating a client with HTTP/2 support enabled:

client = httpx.AsyncClient(http2=True)
...

You can also instantiate a client as a context manager, to ensure that all HTTP connections are nicely scoped, and will be closed once the context block is exited.

async with httpx.AsyncClient(http2=True) as client:
    ...

Proxy

with httpx.Client(proxies="http://localhost:8030") as client:
    ...

환경 변수

HTTP_PROXY, HTTPS_PROXY, ALL_PROXY를 사용하면 된다.

export HTTP_PROXY=http://my-external-proxy.com:1234

# This request will be sent through the proxy
python -c "import httpx; httpx.get('http://example.com')"

# This request will be sent directly, as we set `trust_env=False`
python -c "import httpx; httpx.get('http://example.com', trust_env=False)"

See also

Favorite site