Clash-for-python
clashlite
A Python library for managing Clash core instances with advanced configuration control.
Features
- Start and stop Clash core instances.
- Dynamically update configurations.
- Manage proxies and groups.
- Test node latency.
- Support for temporary configuration files.
Installation
pip install clashlite
Usage
1. Init a clash core instance:
clash = Clash(
config_path: Optional[str] = "..\config.yaml",
exe_path: str = "clash-verge-core.exe",
controller: str = "127.0.0.1:9090",
api_secret: Optional[str] = None,
show_output: bool = False
)
- config: a clash config
..\config.yaml - exe_path: enter the clash core you want to use, or leave blank to use default clash core.
..\clah-verge-core.exe - controller: set the clash external controller address, or leave blankto default. Default value:
127.0.0.1:9090 - api_secret: clash core controller api secret
- show_output:
boolshow clash core output or not.
2. Start and stop
clash.start(wait: int = 5)
launch the clash core.
- wait: the wait time after send the launch command, to ensure the core is fully lunched.
clash.stop()
stop a clash core
快速开始
from clashlite import Clash
# 创建 Clash 实例
clash = Clash(config_path="config.yaml", controller="http://127.0.0.1:9090")
# 启动 Clash 核心
clash.start()
# 获取所有代理组
groups = clash.get_groups()
# 切换到第一个代理组的第一个节点
clash.set_proxy(groups[0], 0)
# 停止 Clash 核心
clash.stop()
API 文档
1. 初始化 Clash 实例
clash = Clash(
config_path: Optional[str] = None,
exe_path: str = "clash-verge-core.exe",
controller: str = "http://127.0.0.1:9090",
api_secret: Optional[str] = None,
show_output: bool = False
)
参数:
config_path: Clash 配置文件路径(可选)。exe_path: Clash 可执行文件路径,默认为当前目录下的clash-verge-core.exe。controller: Clash 控制 API 地址,默认为http://127.0.0.1:9090。api_secret: Clash API 密钥(如果配置文件中已设置,可省略)。show_output: 是否显示 Clash 核心的输出日志。
2. 启动和停止 Clash 核心
-
启动 Clash 核心:
clash.start(wait: int = 5)
参数:
wait: 启动后等待的秒数,确保 Clash 核心完全启动。
-
停止 Clash 核心:
clash.stop()
- 获取当前配置:
config = clash.get_config()
返回: 当前 Clash 配置的字典。
- 切换代理:
clash.switch_proxy(group_name: str, new_proxy: str)
参数:group_name: 代理组名称。new_proxy: 新的代理节点名称。
- 获取所有策略组:
groups = clash.get_groups()
返回: 所有策略组名称的列表。
- 测试节点延迟:
def get_delay(self, target: str, test_url: str = "http://www.example.com", timeout: int = 2000)
参数:test_url: 测试 URL。timeout: 超时时间(毫秒)。
- 设置代理模式:
clash.set_mode(mode: str = "rule")
参数:mode: 代理模式(rule/global/direct)。
Metadata
Release files for clashlite 0.1.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 | Actions |
|---|---|---|---|---|
| clashlite-0.1.0.tar.gz | 6.4 kB | Without provenance | Details for clashlite-0.1.0.tar.gz |
Release files / clashlite-0.1.0.tar.gz
| Download URL | clashlite-0.1.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf2b6ba628f530d170fad3d025a5bd51300cfd193bc92caba7de6bfceb373524
|
|
BLAKE2b-256 checksum How to use checksums |
a77654efb5ecad6c004fce8a2910d4cbd03989303c76149a396f77e4443d4e6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Security for clashlite 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.