Skip to main content

singbox2proxy

Pip module installs total downloadsRun Tests Upload Python Package to PyPI when a Release is Created

Integrate sing-box proxies into your python applications with ease on any device.

  • sing-box auto-install & easy management
  • zero dependencies for base functionality
  • seamless integration with existing applications
  • batch proxy engine with shared singbox process
  • tuned for best performance and latency in mind

Supported Protocols

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

Installation

Quick Install (no Python required)

Linux / macOS:

curl -fsSL https://raw.githubusercontent.com/nichind/singbox2proxy/main/scripts/install.sh | sh

Windows (PowerShell):

irm https://raw.githubusercontent.com/nichind/singbox2proxy/main/scripts/install.ps1 | iex

By default this downloads a standalone binary. To install via Python/pip instead:

# Linux/macOS
curl -fsSL https://raw.githubusercontent.com/nichind/singbox2proxy/main/scripts/install.sh | sh -s -- --python

# Windows
& ([scriptblock]::Create((irm https://raw.githubusercontent.com/nichind/singbox2proxy/main/scripts/install.ps1))) -Mode python

Standalone Binary (no Python, no pip)

Download a pre-built binary from Releases — just download, put anywhere in PATH, and use:

sb2p "vless://..."

With pip

pip install singbox2proxy 

with uv

uv pip install singbox2proxy 

build from source

git clone https://github.com/nichind/singbox2proxy.git
cd singbox2proxy
pip install -e .

or install directly from GitHub

pip install git+https://github.com/nichind/singbox2proxy.git

Python Usage

Using built-in client powered by curl-cffi or requests

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":"..."}

Chaining

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.

Batch Engine

Run hundreds of proxies through shared sing-box processes (~30 MB per batch instead of per proxy):

from singbox2proxy import SingBoxBatch

# From a list
batch = SingBoxBatch(["vless://...", "trojan://...", "ss://..."])

# From a file (one URL per line, # comments)
batch = SingBoxBatch.from_file("proxies.txt")

# With options
batch = SingBoxBatch(urls, batch_size=30, log_level="error")

Use proxies — each one gets its own SOCKS5 port:

# By index
resp = batch[0].get("https://api.ipify.org?format=json")
print(resp.json())  # {"ip": "..."}

# SOCKS URL for external clients
print(batch[0].socks_url)   # socks5://127.0.0.1:40000

# With requests library
import requests
requests.get("https://example.com", proxies=batch[0].proxies)

# Iterate
for proxy in batch:
    print(proxy.protocol, proxy.socks_url)

Check which ones work:

for result in batch.check(timeout=5, workers=10):
    if result.working:
        print(f"{result.protocol} OK {result.ip} {result.latency_ms:.0f}ms")

# Or check + filter in one go
for proxy in list(batch):
    if not proxy.check().working:
        batch.remove(proxy)
# batch now contains only working proxies

Chain through an upstream proxy:

# Via URL string
batch = SingBoxBatch.from_file("proxies.txt", chain_proxy="trojan://upstream")

# Via existing SingBoxProxy (same API as SingBoxProxy's chain_proxy)
from singbox2proxy import SingBoxProxy
upstream = SingBoxProxy("trojan://upstream")
batch = SingBoxBatch.from_file("proxies.txt", chain_proxy=upstream)

Add/remove at runtime:

# Add more proxies (starts a new sing-box process, returns new handles)
new = batch.add(["trojan://new-one", "vmess://another"])
print(new[0].socks_url)

# Remove a proxy
batch.remove(batch[0])
print(len(batch))  # updated count

Cleanup:

batch.stop()

# Or use as context manager
with SingBoxBatch.from_file("proxies.txt") as batch:
    for proxy in batch:
        proxy.get("https://example.com")

TUN Mode (System-Wide VPN)

Create a virtual network interface to route all system traffic through the proxy. This requires root/administrator privileges.

[!IMPORTANT] Very experimental, use at your own risk.

# Requires root/admin privileges
proxy = SingBoxProxy("vless://...", tun_enabled=True)

# All system traffic is now routed through the proxy
# Use like a normal VPN connection

Relay - Share Your Proxy Connection

Create a shareable proxy server that relays traffic through your existing proxy connection or provides direct internet access:

from singbox2proxy import SingBoxProxy

# Relay through an existing proxy
proxy = SingBoxProxy(
    "vless://original-proxy-url",
    relay_protocol="ss",  # Protocol for the relay server
    relay_host="192.168.1.100",  # Your server's IP (auto-detected if not specified)
    relay_port=8443  # Port for the relay server (auto-assigned if not specified)
)

# Or create a direct connection relay (no proxy URL needed)
direct_relay = SingBoxProxy(
    None,  # No proxy - direct connection
    relay_protocol="ss",
    relay_host="my-server.com",
    relay_port=8443
)

# Get the shareable URL
print(f"Share this URL: {proxy.relay_url}")
# Output: ss://uuid@192.168.1.100:8443?type=tcp&security=none#singbox2proxy-relay

# Keep the proxy running
input("Press Enter to stop...")
proxy.stop()

Supported protocols: vmess, vless, trojan, ss, shadowsocks, socks, http

System Proxy Configuration

Automatically configure your OS proxy settings. This is a great alternative to TUN mode when you don't have root access.

[!NOTE] The system proxy settings will be restored to their original state when the SingBoxProxy instance is closed or goes out of scope, but multiple instances may interfere with each other, may be better to backup your initial settings before using this feature.

# Automatically sets system proxy and restores on exit
with SingBoxProxy("vless://...", set_system_proxy=True) as proxy:
    # Your web browser and other apps will now use the proxy
    print(f"System proxy configured to use {proxy.http_proxy_url}")

CLI

[!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.

Basic Commands

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
# sing-box 1.12.4
#   http   http://127.0.0.1:57539
#   socks  socks5://127.0.0.1:57540
# test:
#   latency  46/129/296 ms (min/avg/max)
#   exit-ip  203.0.113.42
#   result   PASS

Run a sing-box subcommand:

sb2p --cmd version
sb2p -C "check -c config.json"

Batch Proxy Checking

Check proxies from a file (one URL per line):

# Basic check
sb2p --check proxies.txt

# Save working proxies, sorted by latency
sb2p --check proxies.txt -o working.txt

# Tune concurrency
sb2p --check proxies.txt --workers 20 --batch-size 100 --timeout 8

# Check through an upstream proxy (chain)
sb2p "trojan://upstream" --check proxies.txt

# Quiet mode — summary only
sb2p --check proxies.txt -q
# 78/200 working (39%) in 8.1s

# Verbose mode — see dead proxies too
sb2p --check proxies.txt -v

Proxy Chaining

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.

Relay - Share Your Proxy Connection

Create a shareable proxy server that relays traffic through your existing proxy connection, or provides direct internet access from your server:

# Relay through an existing proxy
sb2p "ss://original-proxy" --relay ss

# Direct connection relay (no proxy, just share your server's internet)
sb2p --relay ss

# Output includes a shareable URL + QR code:
#   relay  vless://uuid@your-ip:port?type=tcp&security=none#singbox2proxy-relay

Supported relay protocols: vmess, trojan, ss/shadowsocks, socks, http

Persistent relay URLs with --uuid-seed (same seed = same URL every restart):

[!NOTE] Consider also setting a custom --relay-port to avoid port change, since the default is to auto-assign an available port.

sb2p --relay vmess --uuid-seed "my-persistent-seed" --relay-port 12345
#   relay  vmess://a1b2c3d4-...@203.0.113.42:12345

sb2p --relay vmess --uuid-seed "my-persistent-seed" --relay-port 54321
#   relay  vmess://a1b2c3d4-...@203.0.113.42:54321

Custom host and port:

sb2p "ss://..." --relay ss --relay-host "myserver.com" --relay-port 8443

[!NOTE] QR rendering requires the qrcode package: pip install qrcode

Configuration Management

Generate configuration without starting:

sb2p "vless://..." --config-only

Save configuration to file:

sb2p "vmess://..." --output-config config.json

Logging Options

Enable verbose logging:

sb2p "ss://..." --verbose

Disable all logging:

sb2p "hy2://..." --quiet

TUN Mode (System-Wide VPN)

Enable TUN mode to route all system traffic through the proxy.

# Linux/macOS (requires sudo)
sudo sb2p "vless://..." --tun

# Windows (run as Administrator)
sb2p "vless://..." --tun

[!IMPORTANT] Very experimental, use at your own risk.

System Proxy

Automatically configure your OS to use the proxy.

# Set system proxy on start, restore on stop
sb2p "vless://..." --set-system-proxy

[!NOTE] The system proxy settings will be restored to their original state when the SingBoxProxy instance is closed or goes out of scope, but multiple instances may interfere with each other, may be better to backup your initial settings before using this feature.

Discaimer

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.

Consider leaving a star ⭐

Star History Chart

Metadata

Release files for singbox2proxy 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for singbox2proxy 0.3.4
File Size Uploaded
singbox2proxy-0.3.4.tar.gz 64.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for singbox2proxy 0.3.4
File Interpreter ABI Platform
singbox2proxy-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 120.7 kB

Release files / singbox2proxy-0.3.4.tar.gz

Download URL singbox2proxy-0.3.4.tar.gz
Size 64.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3369b36c9eb9fb827d1b7b8309a39923b1fa4417d50f62b060508e5a83b6d7d7
BLAKE2b-256 checksum
How to use checksums
83b79999646e04a5b5c6af31b5b7e1aaeb3b392d37a456fd4574ef11902dc103
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 3, 2026.

Transparency log

Release files / singbox2proxy-0.3.4-py3-none-any.whl

Download URL singbox2proxy-0.3.4-py3-none-any.whl
Size 56.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2aea894e996824088b0d6fb970aed55d79c572f5cc32478864da7fcdf9c60151
BLAKE2b-256 checksum
How to use checksums
7afab9c879510beed253a87a7ae4c1345ad2d93a791d0d0ecc1ac96ecec7236e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page