Architecture¶
python-v2ray
employs a smart hybrid architecture to achieve both high performance and ease of use. It combines a high-level Python orchestrator with a low-level Go test engine.
The Two Main Components¶
-
Python Orchestrator This is the user-facing part of the library, written entirely in Python. It handles:
- API Layer: Providing the clean, "Pythonic" API (
XrayCore
,ConnectionTester
, etc.). - Configuration Logic: Parsing diverse URI formats and building complex JSON configs.
- Process Management: Starting, stopping, and monitoring the underlying
xray
andhysteria
processes. - Binary Management: Downloading the necessary executables for the user's platform.
- API Layer: Providing the clean, "Pythonic" API (
-
Go Test Engine (
core_engine
) This is a small, self-contained, compiled Go program. Its sole purpose is to perform network operations as fast as possible. It receives a list of test jobs from the Python orchestrator and:- Performs concurrent TCP/SOCKS dialing.
- Measures connection latency to a target URL.
- Reports results (success, failure, latency) back to Python.
Communication Flow¶
The two components communicate via a simple and efficient Inter-Process Communication (IPC) protocol:
- The Python Orchestrator serializes a list of "test jobs" into a JSON string.
- It executes the Go Test Engine as a subprocess.
- It pipes the JSON string to the Go engine's
stdin
. - The Go Engine runs all tests concurrently (using goroutines).
- It gathers the results, serializes them into a JSON string, and prints it to
stdout
. - The Python Orchestrator reads the
stdout
from the subprocess and deserializes the JSON results.
The Best of Both Worlds
This hybrid design allows you to benefit from Python's rapid development and rich ecosystem while leveraging Go's exceptional performance for concurrent networking tasks.