迅雷 XL Download Python SDK
Project description
XL Download Python SDK
XL Download Python SDK 适用于在 Python 脚本或桌面工具中接入迅雷下载能力。
支持平台
| Windows x64 | Windows x86 | macOS Universal | Linux x64 |
|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ |
环境要求
- Python 3.8 或更高版本。
包说明
xunlei-open-dlsdk:主 API 包。xunlei-open-dlsdk-native-windows-x64xunlei-open-dlsdk-native-windows-x86xunlei-open-dlsdk-native-macos-universalxunlei-open-dlsdk-native-linux-x64
pip 安装
在应用虚拟环境中安装主包,并按应用要支持的平台安装对应 native 包。跨平台应用可以同时安装多个 native 包,运行时会加载当前平台对应的动态库。
| 目标平台 | 安装命令 |
|---|---|
| Windows x64 | python -m pip install xunlei-open-dlsdk xunlei-open-dlsdk-native-windows-x64 |
| Windows x86 | python -m pip install xunlei-open-dlsdk xunlei-open-dlsdk-native-windows-x86 |
| macOS Universal | python -m pip install xunlei-open-dlsdk xunlei-open-dlsdk-native-macos-universal |
| Linux x64 | python -m pip install xunlei-open-dlsdk xunlei-open-dlsdk-native-linux-x64 |
例如接入 macOS:
python -m pip install xunlei-open-dlsdk xunlei-open-dlsdk-native-macos-universal
Python import 名称保持为 xl_dl:
from xl_dl import XLDownloadAPI
也可以不安装 native wheel,直接指定本地原生库路径:
export XL_DL_NATIVE_PATH=/absolute/path/to/libdk.dylib
| 平台 | 文件名 |
|---|---|
| Windows x64 / x86 | dk.dll |
| macOS Universal | libdk.dylib |
| Linux x64 | libdk.so |
XL_DL_NATIVE_PATH 必须是绝对路径。适用于无法安装 native wheel 的场景(如 CI 环境、自定义存放路径)。
最小示例
import time
from pathlib import Path
from xl_dl import ERROR_ALREADY_INIT, ERROR_SUCCESS, TASK_STATUS_SUCCEEDED, TASK_STATUS_FAILED, XLDownloadAPI
app_id = "your-app-id"
api_key = "your-api-key"
config_path = "/tmp/xl_dl_sdk_conf"
save_path = "/tmp/ThunderDownload"
Path(config_path).mkdir(parents=True, exist_ok=True)
Path(save_path).mkdir(parents=True, exist_ok=True)
sdk = XLDownloadAPI()
init_result = sdk.init(app_id, "1.0", config_path, save_tasks=True)
if init_result not in (ERROR_SUCCESS, ERROR_ALREADY_INIT):
raise RuntimeError(f"init failed: {init_result}")
code, login_token, _expires_in, message = sdk.get_login_token(api_key)
if code != 0:
raise RuntimeError(f"get loginToken failed: {message}")
login_result, session_id = sdk.login(login_token)
if login_result != ERROR_SUCCESS:
raise RuntimeError(f"login failed: {login_result}")
create_result, task_id = sdk.create_p2sp_task(
"https://example.com/file.zip",
save_path,
"file.zip",
)
if create_result == ERROR_SUCCESS:
sdk.start_task(task_id)
while True:
result, state = sdk.get_task_state(task_id)
if state is None:
break
print(f"\rstate:{state.state_code} downloaded:{state.downloaded_size}/{state.total_size} speed:{state.speed}", end="", flush=True)
if state.state_code in (TASK_STATUS_SUCCEEDED, TASK_STATUS_FAILED):
print()
break
time.sleep(1)
sdk.uninit()
完整可运行示例见 examples/basic_download.py。
相关文档
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 xunlei_open_dlsdk-1.0.0.tar.gz.
File metadata
- Download URL: xunlei_open_dlsdk-1.0.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf83362042ab6e22de03f770422da384d6eccfa140ee045933045a7dd2c51f31
|
|
| MD5 |
c9f10cab7a784044dca571809522c21d
|
|
| BLAKE2b-256 |
daf8775d8088891d5c649b39389c2c0f753b74d491e079b8a73019a8400eaa65
|
File details
Details for the file xunlei_open_dlsdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: xunlei_open_dlsdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7add4e7cf733fa5340a4550008ca9872a5ef6a14438b62dcd70d5d13ce866e4a
|
|
| MD5 |
54f5106e911342d6ea5eedcd191ec529
|
|
| BLAKE2b-256 |
2bf5a23e81b99b9ca1dba9929b4a4333e059704f7329376cce3b33025dd19371
|