Skip to main content

🐍 Convert v2ray (vless://, vmess://, ss:// , trojan://) to local socks5:// & http:// proxies

Project description

Check out nichind/singbox2proxy, a similar library with better performance and more features, supporting SingBox links (hy2://, tuic://, etc.) in addition to V2Ray links, chaining support & built-in http client.

v2ray2proxy

A Python library to convert V2Ray configuration links (vmess://, vless://, ss://, trojan://) to usable HTTP and SOCKS5 proxies for Python HTTP clients.

Features

  • Convert V2Ray links to local proxy instances
  • Automatic V2Ray core download - no external installation needed
  • Support for all major V2Ray protocols:
    • VMess
    • VLESS
    • Shadowsocks
    • Trojan
  • Proxy pool for load balancing and failover
  • Works with both synchronous and asynchronous HTTP clients
  • Clean, Pythonic API

Installation

pip install v2ray2proxy

Usage

Basic Usage

from v2ray2proxy import V2RayProxy
import requests

# Create a proxy from a V2Ray link
proxy = V2RayProxy("vmess://...")

try:
    # Use with requests
    proxies = {
        "http": proxy.http_proxy_url,
        "https": proxy.http_proxy_url
    }
    
    response = requests.get("https://api.ipify.org?format=json", proxies=proxies)
    print(response.json())
finally:
    # Always stop the proxy when done
    proxy.stop()

Using with aiohttp (Async)

import asyncio
import aiohttp
from v2ray2proxy import V2RayProxy

async def main():
    # Create a proxy from a V2Ray link
    proxy = V2RayProxy("vmess://...")
    
    try:
        # Use with aiohttp
        async with aiohttp.ClientSession() as session:
            async with session.get(
                "https://api.ipify.org?format=json",
                proxy=proxy.http_proxy_url
            ) as response:
                data = await response.json()
                print(data)
    finally:
        # Always stop the proxy when done
        proxy.stop()

asyncio.run(main())

Proxy Pool for Load Balancing

from v2ray2proxy import V2RayPool
import requests

# Create a pool with multiple proxies
links = [
    "vmess://...",
    "vless://...",
    "trojan://..."
]

pool = V2RayPool(v2ray_links=links)

try:
    # Get the fastest proxy from the pool
    proxy = pool.get_fastest_proxy()
    
    # Use the proxy
    proxies = {
        "http": proxy.http_proxy_url,
        "https": proxy.http_proxy_url
    }
    
    response = requests.get("https://api.ipify.org?format=json", proxies=proxies)
    print(response.json())
    
    # You can also get a proxy using different strategies
    # Round-robin
    proxy = pool.get_proxy(strategy="round-robin")
    # Random
    proxy = pool.get_proxy(strategy="random")
    
    # Get proxy URLs directly from the pool
    http_url = pool.http_proxy_url()
    socks5_url = pool.socks5_proxy_url()
finally:
    # Always stop the pool when done
    pool.stop()

Command Line Usage

# Start a proxy and print the details
python -m v2ray2proxy "vmess://..."

# Test the proxy after starting
python -m v2ray2proxy "vmess://..." --test

# Specify custom ports
python -m v2ray2proxy "vmess://..." --http-port 8080 --socks-port 1080

# Start a proxy pool with multiple instances of the same link
python -m v2ray2proxy "vmess://..." --pool --pool-size 3

Supported Link Types

  • VMess: vmess://... - V2Ray's VMess protocol
  • VLESS: vless://... - V2Ray's VLESS protocol
  • Shadowsocks: ss://... - Shadowsocks protocol
  • Trojan: trojan://... - Trojan protocol

Advanced Usage

Custom Ports

from v2ray2proxy import V2RayProxy

# Specify custom ports
proxy = V2RayProxy(
    "vmess://...",
    http_port=8080,
    socks_port=1080
)

Checking Proxy Health

from v2ray2proxy import V2RayPool

pool = V2RayPool(v2ray_links=["vmess://...", "vmess://..."])

# Check health of all proxies
health_status = pool.check_health()
print(health_status)

# Automatically restart unhealthy proxies
pool.auto_failover()

Configuration Only Mode

If you only want to generate the configuration without starting the proxy:

from v2ray2proxy import V2RayProxy
import json

proxy = V2RayProxy("vmess://...", config_only=True)

# Get the V2Ray configuration
config = proxy.generate_config()
print(json.dumps(config, indent=2))

# Create the config file
config_path = proxy.create_config_file()
print(f"Config file created at: {config_path}")

License

MIT

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

v2ray2proxy-0.3.2.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

v2ray2proxy-0.3.2-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file v2ray2proxy-0.3.2.tar.gz.

File metadata

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

File hashes

Hashes for v2ray2proxy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 2a21922ee2545277590e047f6339b4e8d23ce66311625000a283aa6943ba6392
MD5 654503c9f475cd71f8f671eba8d10e83
BLAKE2b-256 6f733d07de86e9d6dcf6e343472d4c3ee0f208db089caf9a75c502d0abb888ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for v2ray2proxy-0.3.2.tar.gz:

Publisher: publish.yml on nichind/v2ray2proxy

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

File details

Details for the file v2ray2proxy-0.3.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for v2ray2proxy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0aa0f402f53c42996ec6c0477dff2464a2aa052376384d99c3afed4fab37216e
MD5 8ff65b1fd0700b2097f62310440581d3
BLAKE2b-256 80bbc9597414fd2860566e6e7a9fc653fbad1c59f674be2a28c011ab7e053a38

See more details on using hashes here.

Provenance

The following attestation bundles were made for v2ray2proxy-0.3.2-py3-none-any.whl:

Publisher: publish.yml on nichind/v2ray2proxy

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