The aiohttp-socks5
package provides a SOCKS5 proxy connector for aiohttp.
- Python >= 3.8
- aiohttp >= 3.0.0
pip install git+https://github.com/HMaker/aiohttp-socks5.git@latest
import asyncio
import aiohttp
from aiohttp_socks5 import SOCKSConnector
async def print_ip(proxy: str):
async with aiohttp.ClientSession(connector=SOCKSConnector()) as session:
# you can set SOCKS5 or HTTP proxies per request below
async with session.get("https://api.ipify.org?format=json", proxy=proxy) as response:
print(await response.json())
asyncio.run(print_ip("socks5://user:[email protected]:1080"))
Unlike aiohttp-socks, aiohttp-socks5
support proxies
per request and allows you to rotate proxies without recreating aiohttp sessions.