A simple Python proxy module that manages Xray core process.
Project description
Xray Proxy Manager
A simple Python proxy module that supports the Vmess protocol. It automatically manages the V2Ray/Xray core process, eliminating the need for users to manually install or configure external proxy software.
Workflow Overview
- Initialization: The user provides a subscription URL and optionally a path for static files.
- Core Management: The module checks if the Xray core is present in the specified (or default) directory. If not, it automatically downloads and unzips the appropriate version for the platform.
- Subscription Parsing: It fetches the subscription URL, decodes the content, and parses the Vmess nodes.
- Latency Testing: It generates a multi-port configuration to test all nodes concurrently against a target URL (e.g., Google) to find the fastest node.
- Proxy Execution: Once the best node is selected, it generates a specific configuration for that node and starts the Xray core process.
- Context Management: The proxy runs within a context manager, ensuring the process is cleanly terminated when the block exits.
Directory Structure
xray-proxy-manager/
├── src/
│ └── xray_proxy_manager/ # Core package
│ ├── __init__.py
│ ├── manager.py # Core process management
│ ├── core.py # Xray core download and management
│ ├── subscription.py # Subscription parsing
│ ├── config.py # Configuration generation
│ └── static/ # Directory for automatically downloaded xray core and config files
├── examples/
│ └── demo.py # Demo script
├── pyproject.toml # Project configuration
└── README.md
Installation
pip install .
Or
pip install xray-proxy-manager
Quick Start
1. Import Module
from xray_proxy_manager import XrayProxyManager
2. Initialize and Use
import requests
from loguru import logger
from xray_proxy_manager import XrayProxyManager
# Your subscription URL
SUB_URL = "https://example.com/subscribe"
def main():
# Initialize manager
# By default, core files are downloaded to ~/.xray_proxy_manager
manager = XrayProxyManager(SUB_URL)
# Or specify a custom path
# manager = XrayProxyManager(SUB_URL, static_path="./my_xray_core")
# Method 1: Automatically test speed and use the fastest node (Recommended)
logger.info("Finding the fastest node and starting proxy...")
try:
# start_fastest will automatically download core, parse subscription, test speed, and start proxy
with manager.start_fastest(test_url="https://www.google.com", timeout=2) as proxies:
logger.info(f"Proxy ready: {proxies}")
logger.info("Accessing ipinfo.io ...")
resp = requests.get("https://ipinfo.io/json", proxies=proxies, timeout=10)
logger.success(f"Success: {resp.json()}")
except Exception as e:
logger.error(f"Error: {e}")
if __name__ == "__main__":
main()
Notes
- This project automatically downloads the Xray core file. The default storage path is
~/.xray_proxy_manager. - You can specify a custom storage path via the
static_pathparameter during initialization. - Only supports Vmess protocol subscriptions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xray_proxy_manager-0.1.0.tar.gz.
File metadata
- Download URL: xray_proxy_manager-0.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5af15d7fc335dd9a4e15d9304afbf65cb504f146f9c683b231847524821e8c95
|
|
| MD5 |
5c429a019d7005fd185c214c59dce802
|
|
| BLAKE2b-256 |
a39b26856a5fb206fd253b7aab07bdc0cf9720f4c6582760b5e93b665c86c30a
|
File details
Details for the file xray_proxy_manager-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xray_proxy_manager-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3a1a084220d11d1a74c398d3a0d17fec400979ec94b33cef930e246df420a0e
|
|
| MD5 |
ac5ebe6250fdb3827fb85259be64a3fe
|
|
| BLAKE2b-256 |
298858a34cafd619e63d99fe5d0884b79dba73fad324994e482eb8940d551790
|