Skip to main content

Python Proxy Headers

Documentation Status PyPI version

Extensions for Python HTTP libraries to support sending and receiving custom proxy headers during HTTPS CONNECT tunneling.

The Problem

When making HTTPS requests through a proxy, the connection is established via a CONNECT tunnel. During this process:

  1. Sending headers to the proxy - Most Python HTTP libraries don't provide an easy way to send custom headers (like X-ProxyMesh-Country) to the proxy server during the CONNECT handshake.

  2. Receiving headers from the proxy - The proxy's response headers from the CONNECT request are typically discarded, making it impossible to read custom headers (like X-ProxyMesh-IP) that the proxy sends back.

This library solves both problems for popular Python HTTP libraries.

Supported Libraries

Library Module Use Case
urllib3 urllib3_proxy_manager Low-level HTTP client
requests requests_adapter Simple HTTP requests
aiohttp aiohttp_proxy Async HTTP client
httpx httpx_proxy Modern HTTP client
pycurl pycurl_proxy libcurl bindings
cloudscraper cloudscraper_proxy Cloudflare bypass
autoscraper autoscraper_proxy Automatic web scraping

Installation

pip install python-proxy-headers

Or install the client extra you need. Each extra pins a range that CI tests:

pip install 'python-proxy-headers[requests]'
pip install 'python-proxy-headers[urllib3]'
pip install 'python-proxy-headers[httpx]'
pip install 'python-proxy-headers[aiohttp]'
pip install 'python-proxy-headers[pycurl]'
pip install 'python-proxy-headers[cloudscraper]'
pip install 'python-proxy-headers[autoscraper]'

The httpx extra is httpx>=0.28,<1. Importing python_proxy_headers.httpx_proxy on httpx 1.x raises ImportError. See the httpx docs. Proxy header names are specific to your provider; ProxyMesh documents theirs at docs.proxymesh.com.

Note: This package has no required dependencies. Install only the extra you need.

Quick Start

requests

from python_proxy_headers.requests_adapter import ProxySession

with ProxySession(proxy_headers={'X-ProxyMesh-Country': 'US'}) as session:
    session.proxies = {'https': 'http://user:pass@proxy.example.com:8080'}
    response = session.get('https://httpbin.org/ip')
    
    # Proxy headers are merged into response.headers
    print(response.headers.get('X-ProxyMesh-IP'))

httpx

from python_proxy_headers.httpx_proxy import get

response = get(
    'https://httpbin.org/ip',
    proxy='http://user:pass@proxy.example.com:8080'
)

# Proxy CONNECT response headers are merged into response.headers
print(response.headers.get('X-ProxyMesh-IP'))

aiohttp

import asyncio
from python_proxy_headers.aiohttp_proxy import ProxyClientSession

async def main():
    async with ProxyClientSession() as session:
        async with session.get(
            'https://httpbin.org/ip',
            proxy='http://user:pass@proxy.example.com:8080'
        ) as response:
            # Proxy headers merged into response.headers
            print(response.headers.get('X-ProxyMesh-IP'))

asyncio.run(main())

pycurl (low-level)

import pycurl
from python_proxy_headers.pycurl_proxy import set_proxy_headers, HeaderCapture

c = pycurl.Curl()
c.setopt(pycurl.URL, 'https://httpbin.org/ip')
c.setopt(pycurl.PROXY, 'http://proxy.example.com:8080')

# Add these two lines to any existing pycurl code
set_proxy_headers(c, {'X-ProxyMesh-Country': 'US'})
capture = HeaderCapture(c)

c.perform()

print(capture.proxy_headers)  # Headers from proxy CONNECT response
c.close()

cloudscraper

from python_proxy_headers.cloudscraper_proxy import create_scraper

# Drop-in replacement for cloudscraper.create_scraper()
scraper = create_scraper(proxy_headers={'X-ProxyMesh-Country': 'US'})
scraper.proxies = {'https': 'http://proxy.example.com:8080'}

response = scraper.get('https://example.com')
# All CloudScraper features (Cloudflare bypass) preserved

Testing

A test harness is included to verify proxy header functionality:

# Header checks and private-hook checks (no proxy credentials)
python test_header_security.py
python test_httpx_guard.py
python test_client_internals.py

# Set your proxy
export PROXY_URL='http://user:pass@proxy.example.com:8080'

# Test all modules
python test_proxy_headers.py

# Test specific modules
python test_proxy_headers.py requests httpx

# Verbose output (show header values)
python test_proxy_headers.py -v

Documentation

For detailed documentation, API reference, and more examples:

Other languages

About

Created by ProxyMesh to help our customers use custom headers to control proxy behavior. Works with any proxy that supports custom headers.

License

MIT License

Metadata

Release files for python-proxy-headers 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-proxy-headers 0.2.5
File Size Uploaded Provenance Actions
python_proxy_headers-0.2.5.tar.gz 22.7 kB With provenance Details for python_proxy_headers-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-proxy-headers 0.2.5
File Interpreter ABI Platform Actions
python_proxy_headers-0.2.5-py3-none-any.whl Python 3 none any Details for python_proxy_headers-0.2.5-py3-none-any.whl

Total release size: 46.4 kB

Release files / python_proxy_headers-0.2.5.tar.gz

Download URL python_proxy_headers-0.2.5.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d696acd89ee1bfe29e8b82725d039abbf8edbeafdd2ec9dc9e11c58006edde04
BLAKE2b-256 checksum
How to use checksums
84f39698b9a1080d965e23f11d0adeae9a883ae61a87ebb9f2b1cea8b0143563
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / python_proxy_headers-0.2.5-py3-none-any.whl

Download URL python_proxy_headers-0.2.5-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed9b672664443f93b465bdd7f15be98355eccfcd62a5890eaf10decf5cb01bdb
BLAKE2b-256 checksum
How to use checksums
99cb8880f3f65edde34e4779a0e052dda3a04f6af82b0ee526f83ac4df292e4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for python-proxy-headers 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for python_proxy_headers-0.2.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page