v2ray2proxy


Namev2ray2proxy JSON
Version 0.2.3 PyPI version JSON
download
home_pageNone
Summary🌩️ Seamlessly convert vless://, vmess://, ss:// , trojan:// to socks/http proxies in your python HTTP clients
upload_time2025-07-13 20:20:52
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords v2ray proxy vless vmess shadowsocks trojan
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
pip install v2ray2proxy
```

## Usage

### Basic Usage

```python
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)

```python
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

```python
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

```bash
# 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

## Requirements

- Python 3.9+
- No external V2Ray installation needed (automatically downloaded)

## Advanced Usage

### Custom Ports

```python
from v2ray2proxy import V2RayProxy

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

### Checking Proxy Health

```python
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:

```python
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}")
```

## Some thoughts

Each v2ray instance eats about ~17MB of RAM on Linux
About 40k avaliable ports (/2 for socks)

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "v2ray2proxy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "v2ray, proxy, vless, vmess, shadowsocks, trojan",
    "author": null,
    "author_email": "nichind <nichinddev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/81/a4/a488af2665b1d79d5165106a8b07f65d394fa451e6ef086a7c6f0eab0a8e/v2ray2proxy-0.2.3.tar.gz",
    "platform": null,
    "description": "# v2ray2proxy\n\nA Python library to convert V2Ray configuration links (vmess://, vless://, ss://, trojan://) to usable HTTP and SOCKS5 proxies for Python HTTP clients.\n\n## Features\n\n- Convert V2Ray links to local proxy instances\n- **Automatic V2Ray core download** - no external installation needed\n- Support for all major V2Ray protocols:\n  - VMess\n  - VLESS\n  - Shadowsocks\n  - Trojan\n- Proxy pool for load balancing and failover\n- Works with both synchronous and asynchronous HTTP clients\n- Clean, Pythonic API\n\n## Installation\n\n```bash\npip install v2ray2proxy\n```\n\n## Usage\n\n### Basic Usage\n\n```python\nfrom v2ray2proxy import V2RayProxy\nimport requests\n\n# Create a proxy from a V2Ray link\nproxy = V2RayProxy(\"vmess://...\")\n\ntry:\n    # Use with requests\n    proxies = {\n        \"http\": proxy.http_proxy_url,\n        \"https\": proxy.http_proxy_url\n    }\n    \n    response = requests.get(\"https://api.ipify.org?format=json\", proxies=proxies)\n    print(response.json())\nfinally:\n    # Always stop the proxy when done\n    proxy.stop()\n```\n\n### Using with aiohttp (Async)\n\n```python\nimport asyncio\nimport aiohttp\nfrom v2ray2proxy import V2RayProxy\n\nasync def main():\n    # Create a proxy from a V2Ray link\n    proxy = V2RayProxy(\"vmess://...\")\n    \n    try:\n        # Use with aiohttp\n        async with aiohttp.ClientSession() as session:\n            async with session.get(\n                \"https://api.ipify.org?format=json\",\n                proxy=proxy.http_proxy_url\n            ) as response:\n                data = await response.json()\n                print(data)\n    finally:\n        # Always stop the proxy when done\n        proxy.stop()\n\nasyncio.run(main())\n```\n\n### Proxy Pool for Load Balancing\n\n```python\nfrom v2ray2proxy import V2RayPool\nimport requests\n\n# Create a pool with multiple proxies\nlinks = [\n    \"vmess://...\",\n    \"vless://...\",\n    \"trojan://...\"\n]\n\npool = V2RayPool(v2ray_links=links)\n\ntry:\n    # Get the fastest proxy from the pool\n    proxy = pool.get_fastest_proxy()\n    \n    # Use the proxy\n    proxies = {\n        \"http\": proxy.http_proxy_url,\n        \"https\": proxy.http_proxy_url\n    }\n    \n    response = requests.get(\"https://api.ipify.org?format=json\", proxies=proxies)\n    print(response.json())\n    \n    # You can also get a proxy using different strategies\n    # Round-robin\n    proxy = pool.get_proxy(strategy=\"round-robin\")\n    # Random\n    proxy = pool.get_proxy(strategy=\"random\")\n    \n    # Get proxy URLs directly from the pool\n    http_url = pool.http_proxy_url()\n    socks5_url = pool.socks5_proxy_url()\nfinally:\n    # Always stop the pool when done\n    pool.stop()\n```\n\n### Command Line Usage\n\n```bash\n# Start a proxy and print the details\npython -m v2ray2proxy \"vmess://...\"\n\n# Test the proxy after starting\npython -m v2ray2proxy \"vmess://...\" --test\n\n# Specify custom ports\npython -m v2ray2proxy \"vmess://...\" --http-port 8080 --socks-port 1080\n\n# Start a proxy pool with multiple instances of the same link\npython -m v2ray2proxy \"vmess://...\" --pool --pool-size 3\n```\n\n## Supported Link Types\n\n- **VMess**: `vmess://...` - V2Ray's VMess protocol\n- **VLESS**: `vless://...` - V2Ray's VLESS protocol\n- **Shadowsocks**: `ss://...` - Shadowsocks protocol\n- **Trojan**: `trojan://...` - Trojan protocol\n\n## Requirements\n\n- Python 3.9+\n- No external V2Ray installation needed (automatically downloaded)\n\n## Advanced Usage\n\n### Custom Ports\n\n```python\nfrom v2ray2proxy import V2RayProxy\n\n# Specify custom ports\nproxy = V2RayProxy(\n    \"vmess://...\",\n    http_port=8080,\n    socks_port=1080\n)\n```\n\n### Checking Proxy Health\n\n```python\nfrom v2ray2proxy import V2RayPool\n\npool = V2RayPool(v2ray_links=[\"vmess://...\", \"vmess://...\"])\n\n# Check health of all proxies\nhealth_status = pool.check_health()\nprint(health_status)\n\n# Automatically restart unhealthy proxies\npool.auto_failover()\n```\n\n### Configuration Only Mode\n\nIf you only want to generate the configuration without starting the proxy:\n\n```python\nfrom v2ray2proxy import V2RayProxy\nimport json\n\nproxy = V2RayProxy(\"vmess://...\", config_only=True)\n\n# Get the V2Ray configuration\nconfig = proxy.generate_config()\nprint(json.dumps(config, indent=2))\n\n# Create the config file\nconfig_path = proxy.create_config_file()\nprint(f\"Config file created at: {config_path}\")\n```\n\n## Some thoughts\n\nEach v2ray instance eats about ~17MB of RAM on Linux\nAbout 40k avaliable ports (/2 for socks)\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\ud83c\udf29\ufe0f Seamlessly convert vless://, vmess://, ss:// , trojan:// to socks/http proxies in your python HTTP clients",
    "version": "0.2.3",
    "project_urls": {
        "Homepage": "https://github.com/nichind/v2ray2proxy",
        "Issues": "https://github.com/nichind/v2ray2proxy/issues"
    },
    "split_keywords": [
        "v2ray",
        " proxy",
        " vless",
        " vmess",
        " shadowsocks",
        " trojan"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8c15064ae00b1a8aed94b35783c5309678995da326f462660db189dee85ed60a",
                "md5": "d683fc1c0582dc74e0929d1a962f1ada",
                "sha256": "ace8182381dd9ab71d74ef8bc958d1a9a578b2cc0f1f7a3896376795ce6f16bd"
            },
            "downloads": -1,
            "filename": "v2ray2proxy-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d683fc1c0582dc74e0929d1a962f1ada",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 25697,
            "upload_time": "2025-07-13T20:20:51",
            "upload_time_iso_8601": "2025-07-13T20:20:51.398511Z",
            "url": "https://files.pythonhosted.org/packages/8c/15/064ae00b1a8aed94b35783c5309678995da326f462660db189dee85ed60a/v2ray2proxy-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "81a4a488af2665b1d79d5165106a8b07f65d394fa451e6ef086a7c6f0eab0a8e",
                "md5": "69fe34321529014756d8e9e7d38ce54e",
                "sha256": "031798fc94f7ebbbd4c4e76ded72589a0dbfe182f277d3a9503693a00bc71e56"
            },
            "downloads": -1,
            "filename": "v2ray2proxy-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "69fe34321529014756d8e9e7d38ce54e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 22314,
            "upload_time": "2025-07-13T20:20:52",
            "upload_time_iso_8601": "2025-07-13T20:20:52.762811Z",
            "url": "https://files.pythonhosted.org/packages/81/a4/a488af2665b1d79d5165106a8b07f65d394fa451e6ef086a7c6f0eab0a8e/v2ray2proxy-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-13 20:20:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nichind",
    "github_project": "v2ray2proxy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "v2ray2proxy"
}
        
Elapsed time: 0.42818s