A SOCKS5 toolchain/framework with programmable addons
Project description
asyncio-socks-server
SOCKS5 server with async Python addon hooks.
Docs · Architecture · Addon model · Public API · 简体中文
Install
pip install asyncio-socks-server
Docker images are versioned:
docker run --rm -p 1080:1080 amaindex/asyncio-socks-server:1.0.1
Run
asyncio_socks_server
asyncio_socks_server --host 127.0.0.1 --port 9050
asyncio_socks_server --auth user:pass
CLI flags:
| Flag | Default | Meaning |
|---|---|---|
--host |
:: |
Bind address |
--port |
1080 |
Bind port |
--auth |
None | username:password |
--log-level |
INFO |
DEBUG, INFO, WARNING, ERROR |
Use from Python
from asyncio_socks_server import Server
Server(host="::", port=1080).run()
With addons:
from asyncio_socks_server import ChainRouter, Server, StatsServer
server = Server(
addons=[
StatsServer(host="127.0.0.1", port=9900),
ChainRouter("10.0.0.5:1080"),
],
)
server.run()
Addon order is execution order.
Model
The core handles SOCKS5 parsing, relay, and hook dispatch. Addons handle policy.
Hook dispatch has three models:
| Model | Hooks | Contract |
|---|---|---|
| Competitive | on_auth, on_connect, on_udp_associate |
First non-None result wins |
| Pipeline | on_data |
Output from one addon becomes input to the next |
| Observational | on_start, on_stop, on_flow_close, on_error |
All applicable addons run |
Built-ins:
ChainRouterfor TCP chain proxyingUdpOverTcpEntryandUdpOverTcpExitServerfor UDP chain proxyingStatsServerfor low-frequency local JSON statsTrafficCounter,FileAuth,IPFilter,Logger
Architecture sketch
Client -- SOCKS5 --> Server --> Target
|
+-- auth / route hooks
+-- data pipeline hooks
+-- flow close hooks
ChainRouter:
Client --> A --> B --> C --> Target
Chain proxying
Each node only knows its next hop:
# A -> B -> C -> target
Server(addons=[ChainRouter("B:1080")]) # A
Server(addons=[ChainRouter("C:1080")]) # B
Server() # C
UDP chain proxying uses TCP between proxy nodes:
from asyncio_socks_server import Server, UdpOverTcpEntry, UdpOverTcpExitServer
entry = Server(addons=[UdpOverTcpEntry("exit-host:9020")])
exit_server = UdpOverTcpExitServer(host="::", port=9020)
Client
from asyncio_socks_server import Address, connect
conn = await connect(
proxy_addr=Address("127.0.0.1", 1080),
target_addr=Address("93.184.216.34", 443),
)
conn.writer.write(b"hello")
await conn.writer.drain()
data = await conn.reader.read(4096)
API surface
Stable imports live at the package root:
from asyncio_socks_server import (
Addon,
Address,
ChainRouter,
Flow,
Server,
StatsServer,
UdpOverTcpEntry,
UdpOverTcpExitServer,
connect,
)
Root exports are the 1.x compatibility contract. Submodules remain importable.
Docs
| Document | Scope |
|---|---|
| Architecture | Core flow, relay design, UDP-over-TCP, Flow context |
| Addon model | Hook contracts, dispatch semantics, built-in addons |
| Public API | 1.x compatibility surface |
Development
git clone https://github.com/Amaindex/asyncio-socks-server.git
cd asyncio-socks-server
uv sync
uv run ruff check .
uv run ruff format --check .
uv run pyright
uv run pytest
uv build
Release
GitHub Actions tests Python 3.12 and 3.13, builds the Python package, and builds Docker images.
Create a GitHub Release from a tag such as v1.0.1. The release workflow publishes the Python package. The Docker workflow publishes semver image tags.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncio_socks_server-1.0.1.tar.gz.
File metadata
- Download URL: asyncio_socks_server-1.0.1.tar.gz
- Upload date:
- Size: 58.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d00f2aaf7453387eef6da6f7132cbb358f42e74f1312d49cd146a1348b4cc88f
|
|
| MD5 |
52b94478b454fbd4a8f96c65b6cd04e3
|
|
| BLAKE2b-256 |
366c9873b937006293c83b10b44f36c62697a17755013dbd20a663a5625c627a
|
File details
Details for the file asyncio_socks_server-1.0.1-py3-none-any.whl.
File metadata
- Download URL: asyncio_socks_server-1.0.1-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c94600c94e4c2fd26e3912f99fe49cecd04544b4438e23a84b4d439ad0de979
|
|
| MD5 |
74d0360ce3ff03654e8eec151bf46dc7
|
|
| BLAKE2b-256 |
67442f6724344181a3e83f39a3b6f30dedf499d913b74d58bb06953eb969eab7
|