Skip to main content

Proxy (HTTP, SOCKS) transports for httpx

Project description

httpx-socks

CI Coverage Status PyPI version versions

The httpx-socks package provides proxy transports for httpx client. SOCKS4(a), SOCKS5(h), HTTP CONNECT proxy supported. It uses python-socks for core proxy functionality.

Requirements

  • Python >= 3.8
  • httpx>=0.28.0,<0.29.0
  • python-socks>=2.4.3,<3.0.0
  • trio>=0.24 (optional)
  • anyio>=3.3.4,<5.0.0 (optional)

Installation

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]

Usage

sync transport

import httpx
from httpx_socks import SyncProxyTransport

def fetch(url):
    transport = SyncProxyTransport.from_url('socks5://user:password@127.0.0.1:1080')
    with httpx.Client(transport=transport) as client:
        res = client.get(url)
        return res.text

async transport (asyncio, trio)

import httpx
from httpx_socks import AsyncProxyTransport

async def fetch(url):
    transport = AsyncProxyTransport.from_url('socks5://user:password@127.0.0.1:1080')
    async with httpx.AsyncClient(transport=transport) as client:
        res = await client.get(url)
        return res.text

secure proxy connections (aka "HTTPS proxies", experimental feature, both sync and async support)

import ssl
import httpx
from httpx_socks import AsyncProxyTransport

async def fetch(url):
    proxy_ssl = ssl.SSLContext(ssl.PROTOCOL_TLS)
    proxy_ssl.verify_mode = ssl.CERT_REQUIRED
    proxy_ssl.load_verify_locations(...)
    
    transport = AsyncProxyTransport.from_url('http://user:password@127.0.0.1:8080', proxy_ssl=proxy_ssl)
    async with httpx.AsyncClient(transport=transport) as client:
        res = await client.get(url)
        return res.text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httpx_socks-0.11.0.tar.gz (118.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

httpx_socks-0.11.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file httpx_socks-0.11.0.tar.gz.

File metadata

  • Download URL: httpx_socks-0.11.0.tar.gz
  • Upload date:
  • Size: 118.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for httpx_socks-0.11.0.tar.gz
Algorithm Hash digest
SHA256 2e2de097d87dfc228dd36e3c5ae0588c836e48159f5996b33cef540497af9b32
MD5 612a6fb676995495268c9bbc0d13e953
BLAKE2b-256 17b41a5a0f67207a117ca554677ccde6f30679d4b5c10a1bf838b93c7644f468

See more details on using hashes here.

File details

Details for the file httpx_socks-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: httpx_socks-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for httpx_socks-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c28ad569ccf681b45437ea8465203cbc082206659b6f623e4ea509b1eb4e8a7
MD5 97ca1e63fce9c12f7f0b9ab46739dfa5
BLAKE2b-256 362a78b08da3f2c8eb4dd31420d0a38ed4fd4cce272dbe6a8a0d154c0300002b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page