The httpx-socks
package provides proxy transports for httpx client.
SOCKS4(a), SOCKS5, HTTP (tunneling) proxy supported.
It uses python-socks for core proxy functionality.
- Python >= 3.6
- httpx >= 0.15.4
- python-socks >= 1.1.0
- async-timeout>=3.0.1 (optional)
- trio>=0.16.0 (optional)
- curio>=1.4 (optional)
only sync proxy support:
pip install httpx-socks
to include optional asyncio support (it requires async-timeout):
pip install httpx-socks[asyncio]
to include optional trio support:
pip install httpx-socks[trio]
to include optional curio support:
pip install httpx-socks[curio]
import httpx
from httpx_socks import SyncProxyTransport
def fetch(url):
transport = SyncProxyTransport.from_url('socks5://user:[email protected]:1080')
with httpx.Client(transport=transport) as client:
res = client.get(url)
return res.text
import httpx
from httpx_socks import AsyncProxyTransport
async def fetch(url):
transport = AsyncProxyTransport.from_url('socks5://user:[email protected]:1080')
async with httpx.AsyncClient(transport=transport) as client:
res = await client.get(url)
return res.text