# 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)
<!--
[![Downloads](https://pepy.tech/badge/httpx-socks/month)](https://pepy.tech/project/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 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)
```python
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)
```python
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/romis2012/httpx-socks",
"name": "httpx-socks",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "httpx asyncio socks socks5 socks4 http proxy",
"author": "Roman Snegirev",
"author_email": "snegiryev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/26/a4/b93909386d9bfc9d43fbb4a35bc33936ff5e6952d03aba8958af3b7dfada/httpx_socks-0.10.0.tar.gz",
"platform": null,
"description": "# httpx-socks\n\n[![CI](https://github.com/romis2012/httpx-socks/actions/workflows/ci.yml/badge.svg)](https://github.com/romis2012/httpx-socks/actions/workflows/ci.yml)\n[![Coverage Status](https://codecov.io/gh/romis2012/httpx-socks/branch/master/graph/badge.svg)](https://codecov.io/gh/romis2012/httpx-socks)\n[![PyPI version](https://badge.fury.io/py/httpx-socks.svg)](https://pypi.python.org/pypi/httpx-socks)\n<!--\n[![Downloads](https://pepy.tech/badge/httpx-socks/month)](https://pepy.tech/project/httpx-socks)\n-->\n\nThe `httpx-socks` package provides proxy transports for [httpx](https://github.com/encode/httpx) client. \nSOCKS4(a), SOCKS5(h), HTTP (tunneling) proxy supported.\nIt uses [python-socks](https://github.com/romis2012/python-socks) for core proxy functionality.\n\n\n## Requirements\n- Python >= 3.6\n- httpx>=0.21.0\n- python-socks>=2.0.0\n- async-timeout>=3.0.1 (optional)\n- trio>=0.16.0 (optional)\n\n\n## Installation\n\nonly sync proxy support:\n```\npip install httpx-socks\n```\n\nto include optional asyncio support (it requires async-timeout):\n```\npip install httpx-socks[asyncio]\n```\n\nto include optional trio support:\n```\npip install httpx-socks[trio]\n```\n\n\n## Usage\n\n#### sync transport\n```python\nimport httpx\nfrom httpx_socks import SyncProxyTransport\n\ndef fetch(url):\n transport = SyncProxyTransport.from_url('socks5://user:password@127.0.0.1:1080')\n with httpx.Client(transport=transport) as client:\n res = client.get(url)\n return res.text\n```\n\n#### async transport (asyncio, trio)\n```python\nimport httpx\nfrom httpx_socks import AsyncProxyTransport\n\nasync def fetch(url):\n transport = AsyncProxyTransport.from_url('socks5://user:password@127.0.0.1:1080')\n async with httpx.AsyncClient(transport=transport) as client:\n res = await client.get(url)\n return res.text\n```\n\n#### secure proxy connections (aka \"HTTPS proxies\", experimental feature, both sync and async support)\n```python\nimport ssl\nimport httpx\nfrom httpx_socks import AsyncProxyTransport\n\nasync def fetch(url):\n proxy_ssl = ssl.SSLContext(ssl.PROTOCOL_TLS)\n proxy_ssl.verify_mode = ssl.CERT_REQUIRED\n proxy_ssl.load_verify_locations(...)\n \n transport = AsyncProxyTransport.from_url('http://user:password@127.0.0.1:8080', proxy_ssl=proxy_ssl)\n async with httpx.AsyncClient(transport=transport) as client:\n res = await client.get(url)\n return res.text\n```\n",
"bugtrack_url": null,
"license": "Apache 2",
"summary": "Proxy (HTTP, SOCKS) transports for httpx",
"version": "0.10.0",
"project_urls": {
"Homepage": "https://github.com/romis2012/httpx-socks"
},
"split_keywords": [
"httpx",
"asyncio",
"socks",
"socks5",
"socks4",
"http",
"proxy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9dfcf55d40f5c158c7acf7a45771019c75a41de756c0a9af6139155a322258f8",
"md5": "bd82695aa25dacc79614144df64975f4",
"sha256": "9345572cc1b279c0878ab976c654a78d9b4b7b446183ec1e03569a480021addb"
},
"downloads": -1,
"filename": "httpx_socks-0.10.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bd82695aa25dacc79614144df64975f4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12844,
"upload_time": "2024-12-10T06:10:26",
"upload_time_iso_8601": "2024-12-10T06:10:26.107837Z",
"url": "https://files.pythonhosted.org/packages/9d/fc/f55d40f5c158c7acf7a45771019c75a41de756c0a9af6139155a322258f8/httpx_socks-0.10.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "26a4b93909386d9bfc9d43fbb4a35bc33936ff5e6952d03aba8958af3b7dfada",
"md5": "f05a60d00368d8ca8dea2797a490f822",
"sha256": "e232e31174de79cc79ca7174bbc159aabb4b95e0ff5cc2d894d33f6cbe1a1096"
},
"downloads": -1,
"filename": "httpx_socks-0.10.0.tar.gz",
"has_sig": false,
"md5_digest": "f05a60d00368d8ca8dea2797a490f822",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 93710,
"upload_time": "2024-12-10T06:10:31",
"upload_time_iso_8601": "2024-12-10T06:10:31.022624Z",
"url": "https://files.pythonhosted.org/packages/26/a4/b93909386d9bfc9d43fbb4a35bc33936ff5e6952d03aba8958af3b7dfada/httpx_socks-0.10.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-10 06:10:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "romis2012",
"github_project": "httpx-socks",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "httpx",
"specs": [
[
">=",
"0.28.0"
],
[
"<",
"0.29.0"
]
]
},
{
"name": "httpcore",
"specs": [
[
"<",
"2.0"
],
[
">=",
"1.0"
]
]
},
{
"name": "anyio",
"specs": [
[
"==",
"3.*"
]
]
},
{
"name": "python-socks",
"specs": [
[
">=",
"2.0.0"
]
]
},
{
"name": "async-timeout",
"specs": [
[
">=",
"3.0.1"
]
]
},
{
"name": "trio",
"specs": [
[
">=",
"0.16.0"
]
]
},
{
"name": "sniffio",
"specs": [
[
">=",
"1.1.0"
]
]
}
],
"lcname": "httpx-socks"
}