Xray tools — Python library
Create and manage Xray-core configuration: inbounds, outbounds, routing and protocol settings. Pure Python implementation.
Links:
Install
Requires Python 3.10 or newer.
pip install xray-tools
Usage
The root object is XRayConfig, imported from xray_tools. Nested sections live in xray_tools.models, and enums such as LogLevel and Network live in xray_tools.enums. Field names match the Xray JSON config.
VLESS and dokodemo-door have typed settings. VLESS clients are added and removed through ProtocolSettingsVless.
Read and write
from_config() builds a config from a JSON string, and to_config() returns one. from_config_file() and to_config_file() read and write a JSON file. Fields whose value is None are omitted.
from xray_tools import XRayConfig
config = XRayConfig.from_config_file("config.json")
config.inbounds[0].settings.client_add(email="next@example.com")
config.to_config_file("config.json", indent=2)
Build a config
from xray_tools import XRayConfig
from xray_tools.enums import LogLevel, Network, Security, SniffingDest
from xray_tools.models import (
Inbound,
Log,
Outbound,
RealitySettings,
Routing,
RoutingRule,
Sniffing,
StreamSettings,
)
from xray_tools.protocols import InboundProtocol, ProtocolSettingsVless
clients = ProtocolSettingsVless()
client = clients.client_add(email="user@example.com", flow="xtls-rprx-vision")
config = XRayConfig(
log=Log(loglevel=LogLevel.warning),
inbounds=[
Inbound(
port=443,
tag="vless-in",
settings=clients,
streamSettings=StreamSettings(
network=Network.tcp,
security=Security.reality,
realitySettings=RealitySettings(
dest="www.microsoft.com:443",
serverNames=["www.microsoft.com"],
privateKey="<private key>",
shortIds=["<short id>"],
),
),
sniffing=Sniffing(destOverride=[SniffingDest.http, SniffingDest.tls]),
)
],
outbounds=[
Outbound(protocol=InboundProtocol.freedom, tag="direct"),
Outbound(protocol=InboundProtocol.blackhole, tag="block"),
],
routing=Routing(
rules=[
RoutingRule(domain=["geosite:category-ads-all"], outboundTag="block"),
RoutingRule(network="tcp,udp", outboundTag="direct"),
]
),
)
print(client.id)
print(config.to_config(indent=2))
client_add generates a UUID when client_id is omitted. The same client (same id and email) is not added twice. client_remove(client_id) deletes by id.
Development
Run tests:
pytest
Metadata
Release files for xray-tools 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xray_tools-0.2.0.tar.gz | 11.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xray_tools-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.8 kB
Release files / xray_tools-0.2.0.tar.gz
| Download URL | xray_tools-0.2.0.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b89c3865059d721330da6509a23e3b5cb6e04ec6b5df271d2bfe33cfd6270a54
|
|
BLAKE2b-256 checksum How to use checksums |
097ca7259f59a20dc9ee6e6c1fc384fa37d9239743d91e67b438851a134a2ea8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logRelease files / xray_tools-0.2.0-py3-none-any.whl
| Download URL | xray_tools-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
823938dd00eef38e3c996cad0cdf24abccdd47a350f81172471f51e2d30a59a7
|
|
BLAKE2b-256 checksum How to use checksums |
f9ac4f9ce6616fa02957e1d053fb29ae86c7053f256c605125a45ee60c5fece5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logSecurity for xray-tools 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for xray_tools-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.