Skip to main content

Proxy (HTTP, SOCKS) transports for httpx

Project description

httpx-socks

CI Coverage Status PyPI version

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

Requirements

  • Python >= 3.6
  • httpx>=0.21.0
  • python-socks>=2.0.0
  • async-timeout>=3.0.1 (optional)
  • trio>=0.16.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.9.2.tar.gz (90.4 kB view details)

Uploaded Source

Built Distribution

httpx_socks-0.9.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for httpx_socks-0.9.2.tar.gz
Algorithm Hash digest
SHA256 cd00570ff81cce99b337ef0baf017bd61df887e9d33d4abeb9a48275386ee1e5
MD5 862fd7547f404aaf37a92fc099a3f767
BLAKE2b-256 1ac7617150082ea7c4a4a716ef76d0f0b7e854b9ca9c8a1a17f7c7568e837b61

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for httpx_socks-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b71537978c50813fb097da8d47e608c82e7bad2c5b4fc7148f36048f6efbd7f0
MD5 ec70fd8766491de85f4a4892f518a04b
BLAKE2b-256 64d5508dcd7cf16a9ba687344bcc75cc43e25389ff390d53c6bddfa3c9ba9f0a

See more details on using hashes here.

Supported by

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