The python-proxy-headers package provides support for handling custom proxy headers when making HTTPS requests in various Python modules.
We currently provide extensions to the following packages:
- urllib3 - a user-friendly HTTP client library for Python
- requests - a simple, yet elegant, HTTP library
- aiohttp - asynchronous HTTP client/server framework for asyncio and Python
- httpx - a next generation HTTP client for Python
None of these modules provide good support for parsing custom response headers from proxy servers. And some of them make it hard to send custom headers to proxy servers. So we at ProxyMesh made these extension modules to support our customers that use Python and want to use custom headers to control our proxy behavior. But these modules can work for handling custom headers with any proxy.
If you are looking for Scrapy support, please see our scrapy-proxy-headers project.
- Proxy CONNECT headers support
- HTTPS tunnel proxy support
- Proxy IP address selection
- Country proxy selection
- Rotating proxy support
- Proxy session management
- Proxy connection pooling
- Async proxy support
- HTTP/2 proxy support
To use these extension modules, you must first do the following:
pip install python-proxy-headers- Install the appropriate package based on the Python library you want to use.
This package does not have any dependencies because we don't know which library you want to use.
The python-proxy-headers package is the perfect solution for developers who need to handle custom proxy headers in their Python applications. It provides a simple and easy-to-use interface for managing proxy connections, and it supports a wide range of popular Python libraries. Whether you're using urllib3, requests, aiohttp, or httpx, this package has you covered.
Here are some quick examples to get you started:
import urllib3 from python_proxy_headers.urllib3 import ProxyHeaders
http = urllib3.PoolManager() proxy_headers = ProxyHeaders(http)
proxy_headers.set_header('X-Proxy-Header', 'value')
response = http.request('GET', 'https://httpbin.org/get', headers=proxy_headers)
print(response.data)
import requests from python_proxy_headers.requests import ProxyHeaders
session = requests.Session() proxy_headers = ProxyHeaders(session)
proxy_headers.set_header('X-Proxy-Header', 'value')
response = session.get('https://httpbin.org/get', headers=proxy_headers)
print(response.text)
import aiohttp from python_proxy_headers.aiohttp import ProxyHeaders
async def main(): async with aiohttp.ClientSession() as session: proxy_headers = ProxyHeaders(session)
# Set a custom header for the proxy
proxy_headers.set_header('X-Proxy-Header', 'value')
# Make a request using the proxy
async with session.get('https://httpbin.org/get', headers=proxy_headers) as response:
print(await response.text())
import httpx from python_proxy_headers.httpx import ProxyHeaders
async def main(): async with httpx.AsyncClient() as client: proxy_headers = ProxyHeaders(client)
# Set a custom header for the proxy
proxy_headers.set_header('X-Proxy-Header', 'value')
# Make a request using the proxy
response = await client.get('https://httpbin.org/get', headers=proxy_headers)
print(response.text)
For detailed documentation, examples, and usage instructions, please see the full documentation.
You can also find more example code in our proxy-examples for python.