Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/romis2012/httpx-socks
Proxy (HTTP, SOCKS) transports for httpx
https://github.com/romis2012/httpx-socks
asyncio http httpx proxy python socks4 socks5 trio
Last synced: 5 days ago
JSON representation
Proxy (HTTP, SOCKS) transports for httpx
- Host: GitHub
- URL: https://github.com/romis2012/httpx-socks
- Owner: romis2012
- License: apache-2.0
- Created: 2020-07-09T11:49:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-10T06:08:19.000Z (about 2 months ago)
- Last Synced: 2025-01-12T13:03:21.323Z (12 days ago)
- Topics: asyncio, http, httpx, proxy, python, socks4, socks5, trio
- Language: Python
- Homepage:
- Size: 1.34 MB
- Stars: 78
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# httpx-socks
[![CI](https://github.com/romis2012/httpx-socks/actions/workflows/ci.yml/badge.svg)](https://github.com/romis2012/httpx-socks/actions/workflows/ci.yml)
[![Coverage Status](https://codecov.io/gh/romis2012/httpx-socks/branch/master/graph/badge.svg)](https://codecov.io/gh/romis2012/httpx-socks)
[![PyPI version](https://badge.fury.io/py/httpx-socks.svg)](https://pypi.python.org/pypi/httpx-socks)The `httpx-socks` package provides proxy transports for [httpx](https://github.com/encode/httpx) client.
SOCKS4(a), SOCKS5(h), HTTP (tunneling) proxy supported.
It uses [python-socks](https://github.com/romis2012/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
```python
import httpx
from httpx_socks import SyncProxyTransportdef 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
```#### async transport (asyncio, trio)
```python
import httpx
from httpx_socks import AsyncProxyTransportasync 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
```#### secure proxy connections (aka "HTTPS proxies", experimental feature, both sync and async support)
```python
import ssl
import httpx
from httpx_socks import AsyncProxyTransportasync 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:[email protected]:8080', proxy_ssl=proxy_ssl)
async with httpx.AsyncClient(transport=transport) as client:
res = await client.get(url)
return res.text
```