python-proxy-headers 0.2.5 requires Python 3.10 or later and doesn't support httpx 1.x. If you run Python 3.10 or newer, upgrade. If you use httpx, install the [httpx] extra so you stay on httpx 0.28.x. Typical request code doesn't need to change.

pip install -U python-proxy-headers
pip install -U 'python-proxy-headers[httpx]'

Python 3.10 or newer is required

0.2.5 needs Python 3.10 or newer. If you're on Python 3.8 or 3.9, stay on 0.2.4 and pin it:

pip install 'python-proxy-headers==0.2.4'

httpx 1.x is not supported

The httpx adapter needs httpx 0.28.x, and httpcore, which that line uses for proxy tunnels. httpx 1.0 removes proxy support, so importing python_proxy_headers.httpx_proxy on httpx 1.x raises an ImportError that starts with python_proxy_headers.httpx_proxy requires httpx>=0.28,<1 and names the httpx version it found. If you installed an httpx 1.0 development build, you will see it.

To stay on a supported httpx, install the extra, which keeps httpx at >=0.28,<1. The httpx page in the package docs covers the adapter in full.

pip install 'python-proxy-headers[httpx]'

Install your client as an extra

You can now install the package together with your HTTP client as an extra, for example pip install 'python-proxy-headers[requests]'. The extra gives you a version range of that client that the package is tested with.

Example: send a country header and read the proxy IP

The httpx adapter sends custom headers on the HTTPS CONNECT handshake and returns the proxy's response headers on the response. Use the Proxy Server Locations article to find the host and port for PROXY_HOST:PORT. X-ProxyMesh-Country works only on the World and Open proxies.

import httpx
from python_proxy_headers import httpx_proxy

proxy = httpx.Proxy(
    'http://USERNAME:PASSWORD@PROXY_HOST:PORT',
    headers={'X-ProxyMesh-Country': 'US'},
)
response = httpx_proxy.get('https://api.ipify.org?format=json', proxy=proxy)
print(response.headers.get('X-ProxyMesh-IP'))

Look for X-ProxyMesh-IP in the printed output. The request and response headers article lists every header ProxyMesh accepts and returns, and the Python proxy configuration article covers the other clients, including requests.

Links: python-proxy-headers 0.2.5 on PyPI, the GitHub release, the full diff from 0.2.4, the changelog, and the package documentation.