## aiohttp-socks
[![CI](https://github.com/romis2012/aiohttp-socks/actions/workflows/ci.yml/badge.svg)](https://github.com/romis2012/aiohttp-socks/actions/workflows/ci.yml)
[![Coverage Status](https://codecov.io/gh/romis2012/aiohttp-socks/branch/master/graph/badge.svg)](https://codecov.io/gh/romis2012/aiohttp-socks)
[![PyPI version](https://badge.fury.io/py/aiohttp-socks.svg)](https://pypi.python.org/pypi/aiohttp-socks)
<!--
[![Downloads](https://pepy.tech/badge/aiohttp-socks/month)](https://pepy.tech/project/aiohttp-socks)
-->
The `aiohttp-socks` package provides a proxy connector for [aiohttp](https://github.com/aio-libs/aiohttp).
Supports SOCKS4(a), SOCKS5(h), HTTP (tunneling) as well as Proxy chains.
It uses [python-socks](https://github.com/romis2012/python-socks) for core proxy functionality.
## Requirements
- Python >= 3.8
- aiohttp >= 3.10.0
- python-socks[asyncio] >= 1.0.1
## Installation
```
pip install aiohttp_socks
```
## Usage
#### aiohttp usage:
```python
import aiohttp
from aiohttp_socks import ProxyType, ProxyConnector, ChainProxyConnector
async def fetch(url):
connector = ProxyConnector.from_url('socks5://user:password@127.0.0.1:1080')
### or use ProxyConnector constructor
# connector = ProxyConnector(
# proxy_type=ProxyType.SOCKS5,
# host='127.0.0.1',
# port=1080,
# username='user',
# password='password',
# rdns=True
# )
### proxy chaining (since ver 0.3.3)
# connector = ChainProxyConnector.from_urls([
# 'socks5://user:password@127.0.0.1:1080',
# 'socks4://127.0.0.1:1081',
# 'http://user:password@127.0.0.1:3128',
# ])
async with aiohttp.ClientSession(connector=connector) as session:
async with session.get(url) as response:
return await response.text()
```
#### aiohttp-socks also provides `open_connection` and `create_connection` functions:
```python
from aiohttp_socks import open_connection
async def fetch():
reader, writer = await open_connection(
proxy_url='socks5://user:password@127.0.0.1:1080',
host='check-host.net',
port=80
)
request = (b"GET /ip HTTP/1.1\r\n"
b"Host: check-host.net\r\n"
b"Connection: close\r\n\r\n")
writer.write(request)
return await reader.read(-1)
```
## Why yet another SOCKS connector for aiohttp
Unlike [aiosocksy](https://github.com/romis2012/aiosocksy), aiohttp_socks has only single point of integration with aiohttp.
This makes it easier to maintain compatibility with new aiohttp versions.
Raw data
{
"_id": null,
"home_page": null,
"name": "aiohttp-socks",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8.0",
"maintainer_email": null,
"keywords": "asyncio, aiohttp, socks, socks5, socks4, http, proxy",
"author": null,
"author_email": "Roman Snegirev <snegiryev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/80/a0/c23cbd322f94346a30c264b1b301320a7ca2259e2a9dae195ec22610ca56/aiohttp_socks-0.9.1.tar.gz",
"platform": null,
"description": "## aiohttp-socks\n\n[![CI](https://github.com/romis2012/aiohttp-socks/actions/workflows/ci.yml/badge.svg)](https://github.com/romis2012/aiohttp-socks/actions/workflows/ci.yml)\n[![Coverage Status](https://codecov.io/gh/romis2012/aiohttp-socks/branch/master/graph/badge.svg)](https://codecov.io/gh/romis2012/aiohttp-socks)\n[![PyPI version](https://badge.fury.io/py/aiohttp-socks.svg)](https://pypi.python.org/pypi/aiohttp-socks)\n<!--\n[![Downloads](https://pepy.tech/badge/aiohttp-socks/month)](https://pepy.tech/project/aiohttp-socks)\n-->\nThe `aiohttp-socks` package provides a proxy connector for [aiohttp](https://github.com/aio-libs/aiohttp). \nSupports SOCKS4(a), SOCKS5(h), HTTP (tunneling) as well as Proxy chains.\nIt uses [python-socks](https://github.com/romis2012/python-socks) for core proxy functionality.\n\n\n## Requirements\n- Python >= 3.8\n- aiohttp >= 3.10.0\n- python-socks[asyncio] >= 1.0.1\n\n## Installation\n```\npip install aiohttp_socks\n```\n\n## Usage\n\n#### aiohttp usage:\n```python\nimport aiohttp\nfrom aiohttp_socks import ProxyType, ProxyConnector, ChainProxyConnector\n\n\nasync def fetch(url):\n connector = ProxyConnector.from_url('socks5://user:password@127.0.0.1:1080')\n \n ### or use ProxyConnector constructor\n # connector = ProxyConnector(\n # proxy_type=ProxyType.SOCKS5,\n # host='127.0.0.1',\n # port=1080,\n # username='user',\n # password='password',\n # rdns=True\n # )\n \n ### proxy chaining (since ver 0.3.3)\n # connector = ChainProxyConnector.from_urls([\n # 'socks5://user:password@127.0.0.1:1080',\n # 'socks4://127.0.0.1:1081',\n # 'http://user:password@127.0.0.1:3128',\n # ])\n async with aiohttp.ClientSession(connector=connector) as session:\n async with session.get(url) as response:\n return await response.text()\n```\n\n#### aiohttp-socks also provides `open_connection` and `create_connection` functions:\n\n```python\nfrom aiohttp_socks import open_connection\n\nasync def fetch():\n reader, writer = await open_connection(\n proxy_url='socks5://user:password@127.0.0.1:1080',\n host='check-host.net',\n port=80\n )\n request = (b\"GET /ip HTTP/1.1\\r\\n\"\n b\"Host: check-host.net\\r\\n\"\n b\"Connection: close\\r\\n\\r\\n\")\n\n writer.write(request)\n return await reader.read(-1)\n```\n\n## Why yet another SOCKS connector for aiohttp\n\nUnlike [aiosocksy](https://github.com/romis2012/aiosocksy), aiohttp_socks has only single point of integration with aiohttp. \nThis makes it easier to maintain compatibility with new aiohttp versions.\n\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Proxy connector for aiohttp",
"version": "0.9.1",
"project_urls": {
"homepage": "https://github.com/romis2012/aiohttp-socks",
"repository": "https://github.com/romis2012/aiohttp-socks"
},
"split_keywords": [
"asyncio",
" aiohttp",
" socks",
" socks5",
" socks4",
" http",
" proxy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "488caeda838978f73418490d6db6fc7102d32b5145f10efb2cef24fb8e53171e",
"md5": "ce3ebc81002e165ced374d6d97a2dd28",
"sha256": "8e30dff7cd21806979bfa76ef5697ca03b05665521bc00e6e0d7fd029c917886"
},
"downloads": -1,
"filename": "aiohttp_socks-0.9.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ce3ebc81002e165ced374d6d97a2dd28",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.0",
"size": 9912,
"upload_time": "2024-11-20T13:50:33",
"upload_time_iso_8601": "2024-11-20T13:50:33.757147Z",
"url": "https://files.pythonhosted.org/packages/48/8c/aeda838978f73418490d6db6fc7102d32b5145f10efb2cef24fb8e53171e/aiohttp_socks-0.9.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "80a0c23cbd322f94346a30c264b1b301320a7ca2259e2a9dae195ec22610ca56",
"md5": "283f0802dbfa7cf1de8d31308c86e63e",
"sha256": "5b320d1bb156fc56d0b31f9de8d5b9b0affbcf1f2df9b8172334dc10e63e4e2f"
},
"downloads": -1,
"filename": "aiohttp_socks-0.9.1.tar.gz",
"has_sig": false,
"md5_digest": "283f0802dbfa7cf1de8d31308c86e63e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.0",
"size": 10337,
"upload_time": "2024-11-20T13:50:35",
"upload_time_iso_8601": "2024-11-20T13:50:35.800640Z",
"url": "https://files.pythonhosted.org/packages/80/a0/c23cbd322f94346a30c264b1b301320a7ca2259e2a9dae195ec22610ca56/aiohttp_socks-0.9.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-20 13:50:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "romis2012",
"github_project": "aiohttp-socks",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "aiohttp-socks"
}