# 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/1a/c7/617150082ea7c4a4a716ef76d0f0b7e854b9ca9c8a1a17f7c7568e837b61/httpx_socks-0.9.2.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.9.2",
"project_urls": {
"Homepage": "https://github.com/romis2012/httpx-socks"
},
"split_keywords": [
"httpx",
"asyncio",
"socks",
"socks5",
"socks4",
"http",
"proxy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "64d5508dcd7cf16a9ba687344bcc75cc43e25389ff390d53c6bddfa3c9ba9f0a",
"md5": "ec70fd8766491de85f4a4892f518a04b",
"sha256": "b71537978c50813fb097da8d47e608c82e7bad2c5b4fc7148f36048f6efbd7f0"
},
"downloads": -1,
"filename": "httpx_socks-0.9.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ec70fd8766491de85f4a4892f518a04b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12878,
"upload_time": "2024-11-06T15:58:35",
"upload_time_iso_8601": "2024-11-06T15:58:35.956689Z",
"url": "https://files.pythonhosted.org/packages/64/d5/508dcd7cf16a9ba687344bcc75cc43e25389ff390d53c6bddfa3c9ba9f0a/httpx_socks-0.9.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1ac7617150082ea7c4a4a716ef76d0f0b7e854b9ca9c8a1a17f7c7568e837b61",
"md5": "862fd7547f404aaf37a92fc099a3f767",
"sha256": "cd00570ff81cce99b337ef0baf017bd61df887e9d33d4abeb9a48275386ee1e5"
},
"downloads": -1,
"filename": "httpx_socks-0.9.2.tar.gz",
"has_sig": false,
"md5_digest": "862fd7547f404aaf37a92fc099a3f767",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 90423,
"upload_time": "2024-11-06T15:58:37",
"upload_time_iso_8601": "2024-11-06T15:58:37.792302Z",
"url": "https://files.pythonhosted.org/packages/1a/c7/617150082ea7c4a4a716ef76d0f0b7e854b9ca9c8a1a17f7c7568e837b61/httpx_socks-0.9.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-06 15:58:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "romis2012",
"github_project": "httpx-socks",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "httpx-socks"
}