Skip to main content

🐳 Use sing-box (v2ray) proxies (VLESS + REALITY, VMess, Trojan, Shadowsocks, Hysteria, Hysteria2, TUIC, WireGuard, SSH) directly in your http clients, with chaining support and easy CLI

Project description

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
  • 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

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.

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, trojan, ss, 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

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:
#   Relay URL: vless://uuid@your-ip:port?type=tcp&security=none#singbox2proxy-relay
#   Share this URL to relay traffic through your server

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

Custom host and port:

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

# Direct connection with custom settings
sb2p --relay ss --relay-host "myserver.com" --relay-port 8443

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singbox2proxy-0.2.7.tar.gz (45.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

singbox2proxy-0.2.7-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file singbox2proxy-0.2.7.tar.gz.

File metadata

  • Download URL: singbox2proxy-0.2.7.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for singbox2proxy-0.2.7.tar.gz
Algorithm Hash digest
SHA256 f31c9e8d5f8ab7050a79219787c957dd1127f6d69e5446a63af5d042d44a30cf
MD5 5642d22cd54c0e1e33696f1a666330c0
BLAKE2b-256 30f0afcc1c1ce24f02b2c2342dceab31dbb1d5a433ce5d202c10765bf7c15cdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for singbox2proxy-0.2.7.tar.gz:

Publisher: publish.yml on nichind/singbox2proxy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file singbox2proxy-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: singbox2proxy-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 44.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for singbox2proxy-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 eca3a45ed95de766566c7bc6082ffede039f217de434bff4d7826a6941d0c138
MD5 af850f1ead97dca1af2fa62d6ccc7c5b
BLAKE2b-256 c48a184375415d983ac639d20ea7528855bd87964f2dff60f36b71b24ab2d1de

See more details on using hashes here.

Provenance

The following attestation bundles were made for singbox2proxy-0.2.7-py3-none-any.whl:

Publisher: publish.yml on nichind/singbox2proxy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page