Integrate sing-box proxies into your python applications with ease.
singbox2proxy is basically a fork of v2ray2proxy with enhanced perfomance and protocol support using sing-box instead of xray-core.
This module supports these sing-box protocols:
- VMess (
vmess://
) - VLESS (
vless://
) - Shadowsocks (
ss://
) - Trojan (
trojan://
) - Hysteria2* (
hy2://
,hysteria2://
) - Hysteria* (
hysteria://
) - TUIC* (
tuic://
) - WireGuard (
wg://
) - SSH (
ssh://
) - HTTP/HTTPS (
http://
,https://
) - SOCKS (
socks://
,socks4://
,socks5://
) - NaiveProxy* (
naive+https://
)
*: Chaining as a middle proxy not supported, according to the sing-box docs
with pip
pip install singbox2proxy
with uv
uv install singbox2proxy
build from source
git clone https://github.com/nichind/singbox2proxy.git
cd singbox2proxy
pip install -e .
Using built-in curl-cffi or requests client
from singbox2proxy import SingBoxProxy
proxy = SingBoxProxy("vless://...")
response = proxy.request("GET", "https://api.ipify.org?format=json") # IF curl-cffi is installed, it will be used; otherwise, requests will be used.
print(response.status_code, response.text) # 200, {"ip":"..."}
Integrating with your own HTTP client
import requests
from singbox2proxy import SingBoxProxy
proxy = SingBoxProxy("hy2://...")
session = requests.Session()
session.proxies = proxy.proxy_for_requests # {"http": "http://127.0.0.1:<port>", "https": "http://127.0.0.1:<port>"}
response = session.get("https://api.ipify.org?format=json")
print(response.status_code, response.text) # 200, {"ip":"..."}
Example with aiohttp
from singbox2proxy import SingBoxProxy
import aiohttp
async def main():
proxy = SingBoxProxy("vmess://...")
async with aiohttp.ClientSession(proxy=proxy.socks5_proxy_url or proxy.http_proxy_url) as session:
async with session.get("https://api.ipify.org?format=json") as response:
print(response.status, await response.text()) # 200, {"ip":"..."}
Chained proxies allow you to route your traffic through multiple proxy servers if you'll ever need more privacy or easy restriction bypass. You can chain multiple proxies together by specifying a chain_proxy
with a gate SingBoxProxy
instance when creating a new SingBoxProxy
.
Note
See what protocols can be used as middleman proxies at supported protocols
from singbox2proxy import SingBoxProxy
proxy1 = SingBoxProxy("vmess://...")
proxy2 = SingBoxProxy("vless://...", chain_proxy=proxy1)
response = proxy2.request("GET", "https://api.ipify.org?format=json")
print(response.status_code, response.text) # 200, {"ip": "<proxy2's IP>"}
# Here, requests made through `proxy2` will first go through `proxy1`, then proxy1 will forward the request to proxy2, and finally proxy2 will send the request to the target server.
Note
If the singbox2proxy
or sb2p
command isn't working in your terminal, use python -m singbox2proxy <command>
, uv run -m singbox2proxy <command>
, etc. instead.
Start a single proxy:
sb2p "vmess://eyJ2IjoiMiIsInBzIj..."
Specify custom ports:
sb2p "ss://..." --http-port 8080 --socks-port False # Socks disabled
Test the proxy connection:
sb2p "trojan://..." --test
Chain multiple proxies (traffic flows: you -> proxy1 -> proxy2 -> target):
sb2p "vmess://..." "vless://..." "hy2://..." --chain
Note
See what protocols can be used as middleman proxies at supported protocols
The first URL becomes the entry point, and the last URL connects to the target server.
Generate configuration without starting:
sb2p "vless://..." --config-only
Save configuration to file:
sb2p "vmess://..." --output-config config.json
Enable verbose logging:
sb2p "ss://..." --verbose
Disable all logging:
sb2p "hy2://..." --quiet
I'm not responsible for possible misuse of this software. Please use it in accordance with the law and respect the terms of service of the services you access through proxies.