https://github.com/hiddify/xtlsapi
Python library to communicate with xray core
https://github.com/hiddify/xtlsapi
Last synced: 11 months ago
JSON representation
Python library to communicate with xray core
- Host: GitHub
- URL: https://github.com/hiddify/xtlsapi
- Owner: hiddify
- License: unlicense
- Created: 2023-01-13T18:11:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-16T19:15:31.000Z (over 1 year ago)
- Last Synced: 2025-06-18T19:17:27.015Z (12 months ago)
- Language: Python
- Homepage:
- Size: 2.91 MB
- Stars: 60
- Watchers: 6
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# xtlsapi
[](https://codecov.io/gh/hiddify/xtlsapi)
[](https://github.com/hiddify/xtlsapi/actions/workflows/main.yml)
Python library to communicate with xray core
## Install it from PyPI
```bash
pip install xtlsapi
```
## Usage
```py
from xtlsapi import XrayClient, utils, exceptions
xray_client = XrayClient('1.2.3.4', 1234)
user_id = utils.generate_random_user_id()
user_email = utils.generate_random_email()
inbound_tag = 'inbound-tag'
# Get stats
print(utils.human_readable_bytes(xray_client.get_client_download_traffic('user-email@mail.com')))
print(utils.human_readable_bytes(xray_client.get_client_upload_traffic('user-email@mail.com')))
print(utils.human_readable_bytes(xray_client.get_inbound_download_traffic(inbound_tag)))
print(utils.human_readable_bytes(xray_client.get_inbound_upload_traffic(inbound_tag)))
# Add & Remove client
user = xray_client.add_client(inbound_tag, user_id, user_email)
if user:
print(user)
xray_client.remove_client(inbound_tag, user_email)
# restart logger
xray_client.restart_logger()
```
## Development
Read the [CONTRIBUTING.md](CONTRIBUTING.md) file.