## 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.6
- aiohttp >= 2.3.2
- 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": "https://github.com/romis2012/aiohttp-socks",
"name": "aiohttp-socks",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "asyncio aiohttp socks socks5 socks4 http proxy",
"author": "Roman Snegirev",
"author_email": "snegiryev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/41/72/e6bb21b989a433690a326d8f6524533cca54adf10b4627bb935b42972f76/aiohttp_socks-0.9.0.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.6\n- aiohttp >= 2.3.2\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",
"summary": "Proxy connector for aiohttp",
"version": "0.9.0",
"project_urls": {
"Homepage": "https://github.com/romis2012/aiohttp-socks"
},
"split_keywords": [
"asyncio",
"aiohttp",
"socks",
"socks5",
"socks4",
"http",
"proxy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c06826a6d4a67ce47125ebedf0316c4dc7ea71f692a2c3d506e25dbfd515db6c",
"md5": "372c78fcdbaff28f841f7a65ebc99e5c",
"sha256": "90a8211fd5b904ccbd010900105f1fd2dab20ae8a07df508df399036ad8d3d88"
},
"downloads": -1,
"filename": "aiohttp_socks-0.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "372c78fcdbaff28f841f7a65ebc99e5c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 9679,
"upload_time": "2024-07-31T06:23:07",
"upload_time_iso_8601": "2024-07-31T06:23:07.955185Z",
"url": "https://files.pythonhosted.org/packages/c0/68/26a6d4a67ce47125ebedf0316c4dc7ea71f692a2c3d506e25dbfd515db6c/aiohttp_socks-0.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4172e6bb21b989a433690a326d8f6524533cca54adf10b4627bb935b42972f76",
"md5": "77be46d1febc1df124a7e01f1ed85f81",
"sha256": "22159a1af026b229cfe5ea007e065bb3fe56385a951a82623a6f4588a6758003"
},
"downloads": -1,
"filename": "aiohttp_socks-0.9.0.tar.gz",
"has_sig": false,
"md5_digest": "77be46d1febc1df124a7e01f1ed85f81",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10201,
"upload_time": "2024-07-31T06:23:09",
"upload_time_iso_8601": "2024-07-31T06:23:09.795879Z",
"url": "https://files.pythonhosted.org/packages/41/72/e6bb21b989a433690a326d8f6524533cca54adf10b4627bb935b42972f76/aiohttp_socks-0.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-31 06:23:09",
"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"
}