CLI-first AutoDL console automation powered by Playwright.
Project description
autodlctl
autodlctl 是一个基于 Playwright 的 AutoDL 控制台 CLI 工具,目标是把实例查询、开关机、详情读取、余额查询和登录状态保存做成可脚本化的命令行流程。
当前版本以 CLI 为主,适合:
- 在没有企业认证 API 的前提下,用浏览器自动化管理 AutoDL 实例
- 把登录态、实例选择、筛选和 SSH 信息提取接到脚本里
- 后续继续扩展成更完整的 AutoDL 自动化工具链
功能
auth: 打开浏览器,等待手动登录并保存 Playwright storage statelist: 列出实例并支持筛选、排序、限制条数detail: 读取实例详情面板和宿主机悬浮信息start: 启动实例,并在运行后复制 SSH 命令和密码stop: 关闭实例inspect/status: 输出当前页面可见控件和页面快照balance: 查询账户余额页中的当前余额run: 运行一组通用浏览器步骤,便于调试和扩展
安装
从 PyPI 安装
pip install autodlctl
playwright install chromium
说明:
pip install autodlctl只安装 Python 包,不会自动下载浏览器- 首次运行时如果检测到 Chromium 缺失,CLI 会尝试自动执行
playwright install chromium - 更稳妥的方式仍然是先手动执行一次
playwright install chromium
本地开发安装
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .[dev]
playwright install chromium
快速开始
1. 登录并保存状态
autodlctl auth --headless false --pause-seconds 180
该命令会打开 AutoDL 控制台,优先使用本机 Chrome 渠道,并使用 .autodl/auth-profile 作为持久浏览器配置;如果系统中未安装 Chrome,则自动回退到 Playwright 自带的 Chromium。命令在确认登录成功后会尽快保存登录态并退出;--pause-seconds 表示最长等待时间,不会在超时前提前终止。默认将登录态保存到 .autodl/storage_state.json。
如果验证码持续失败,建议保持相同的 --profile-dir 继续重试,避免频繁删除该目录;如需重新初始化登录环境,可删除该目录后重新登录。
2. 查询实例
autodlctl list
在已按默认路径保存登录态的情况下,可直接运行 autodlctl list;程序将默认读取 .autodl/storage_state.json。
按条件筛选:
autodlctl list \
--storage-state .autodl/storage_state.json \
--gpu-model 4090 \
--min-gpu-free 1 \
--sort-by rentable_until
3. 查看详情
autodlctl detail \
--storage-state .autodl/storage_state.json \
--instance "你的实例名称或实例 ID"
4. 开机 / 关机
autodlctl start \
--storage-state .autodl/storage_state.json \
--instance "你的实例名称或实例 ID"
autodlctl stop \
--storage-state .autodl/storage_state.json \
--instance "你的实例名称或实例 ID"
无卡模式开机:
autodlctl start \
--storage-state .autodl/storage_state.json \
--instance "你的实例名称或实例 ID" \
--mode nocard
5. 查询余额
autodlctl balance \
--storage-state .autodl/storage_state.json
通用步骤模式
如果你想调试页面元素或临时跑一串 Playwright 操作,可以用 run:
autodlctl run \
--storage-state .autodl/storage_state.json \
--steps '[{"op":"wait_for","selector":"body"},{"op":"title"}]'
也支持兼容旧脚本入口:
python3 tools/autodl_console.py list --storage-state .autodl/storage_state.json
命令输出
CLI 统一输出 JSON,便于在 shell、Python 或其他脚本中消费。0.x 阶段会尽量保持这些顶层键稳定:
successreasoncontainer_idaccessdetailinstancesfiltersort
项目结构
src/autodlctl/
cli.py # argparse 入口与命令分发
runtime.py # 浏览器启动、storage state、资源关闭
parsing.py # 文本规范化、cookie 检查、列表过滤排序
page_ops.py # 页面交互与详情/tooltip 抓取
commands/
generic.py # run / inspect / status
instances.py # start / stop / detail / list / auth
account.py # balance
tools/autodl_console.py # 旧入口兼容包装
开发与测试
pytest
python -m build
如果只想验证 CLI 入口:
python -m autodlctl --help
autodlctl --help
发布到 PyPI
项目使用 GitHub Actions + Trusted Publisher。
建议发布流程:
- 先在 TestPyPI 配置 trusted publisher
- 在 GitHub Actions 手动触发
release.yml,选择testpypi - 验证安装与命令入口
- 在正式 PyPI 配置 trusted publisher
- 更新版本号
- 推送
vX.Y.Ztag 触发正式发布
本地构建命令:
python -m build
twine check dist/*
注意事项
- 这个项目依赖 AutoDL 当前网页结构,页面 DOM 变动后可能需要调整选择器
- storage state 实际上就是浏览器登录态,建议只保存在本地可信环境
- 某些操作会弹出确认框或宿主机悬浮层,CI 无法完全替代真实人工验证
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 autodlctl-0.1.1.tar.gz.
File metadata
- Download URL: autodlctl-0.1.1.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbb323cf75cf4a6256989f4110752d423eadc318dd83d6547fefae5c38d3ad6e
|
|
| MD5 |
5d4afdfed8e5bcbeb8eeb90984ac902b
|
|
| BLAKE2b-256 |
5456c74f5d3e7aa82c530bba3aba4e393faa917377885eb0ece3e980a532baff
|
Provenance
The following attestation bundles were made for autodlctl-0.1.1.tar.gz:
Publisher:
release.yml on zlh123123/autodlctl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autodlctl-0.1.1.tar.gz -
Subject digest:
cbb323cf75cf4a6256989f4110752d423eadc318dd83d6547fefae5c38d3ad6e - Sigstore transparency entry: 1250801072
- Sigstore integration time:
-
Permalink:
zlh123123/autodlctl@52e88212df8b4f5779547215c606f555eaae7529 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zlh123123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@52e88212df8b4f5779547215c606f555eaae7529 -
Trigger Event:
push
-
Statement type:
File details
Details for the file autodlctl-0.1.1-py3-none-any.whl.
File metadata
- Download URL: autodlctl-0.1.1-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5bc793fc634311eea85fcf10016edb940df8daab26595b1f8f58697f480e819
|
|
| MD5 |
35591e67c6f9918598becbc2dbbad28e
|
|
| BLAKE2b-256 |
1f894997e65ff4b2ff0080f61df0cf2ed02ed87c571e121bb00647d513882db0
|
Provenance
The following attestation bundles were made for autodlctl-0.1.1-py3-none-any.whl:
Publisher:
release.yml on zlh123123/autodlctl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autodlctl-0.1.1-py3-none-any.whl -
Subject digest:
a5bc793fc634311eea85fcf10016edb940df8daab26595b1f8f58697f480e819 - Sigstore transparency entry: 1250801102
- Sigstore integration time:
-
Permalink:
zlh123123/autodlctl@52e88212df8b4f5779547215c606f555eaae7529 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zlh123123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@52e88212df8b4f5779547215c606f555eaae7529 -
Trigger Event:
push
-
Statement type: