Skip to main content

CLI-first AutoDL console automation powered by Playwright.

Project description

autodlctl

autodlctl 是一个基于 Playwright 的 AutoDL 控制台 CLI 工具,目标是把实例查询、开关机、详情读取、余额查询和登录状态保存做成可脚本化的命令行流程。

当前版本以 CLI 为主,适合:

  • 在没有企业认证 API 的前提下,用浏览器自动化管理 AutoDL 实例
  • 把登录态、实例选择、筛选和 SSH 信息提取接到脚本里
  • 后续继续扩展成更完整的 AutoDL 自动化工具链

功能

  • auth: 打开浏览器,等待手动登录并保存 Playwright storage state
  • list: 列出实例并支持筛选、排序、限制条数
  • 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 \
  --save-storage-state .autodl/storage_state.json

这条命令会打开 AutoDL 控制台,给你一段时间手动登录。命令结束后会把登录态保存到 .autodl/storage_state.json

2. 查询实例

autodlctl list \
  --storage-state .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 阶段会尽量保持这些顶层键稳定:

  • success
  • reason
  • container_id
  • access
  • detail
  • instances
  • filter
  • sort

项目结构

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。

建议发布流程:

  1. 先在 TestPyPI 配置 trusted publisher
  2. 在 GitHub Actions 手动触发 release.yml,选择 testpypi
  3. 验证安装与命令入口
  4. 在正式 PyPI 配置 trusted publisher
  5. 更新版本号
  6. 推送 vX.Y.Z tag 触发正式发布

本地构建命令:

python -m build
twine check dist/*

注意事项

  • 这个项目依赖 AutoDL 当前网页结构,页面 DOM 变动后可能需要调整选择器
  • storage state 实际上就是浏览器登录态,建议只保存在本地可信环境
  • 某些操作会弹出确认框或宿主机悬浮层,CI 无法完全替代真实人工验证

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autodlctl-0.1.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autodlctl-0.1.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file autodlctl-0.1.0.tar.gz.

File metadata

  • Download URL: autodlctl-0.1.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for autodlctl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0363ccc1e4b4d3c321382e55e6daf1ee0bec9b847e1b5ac6071f8fd659e8710
MD5 aa410ae638cc676474ddbd7a9a322212
BLAKE2b-256 86b718f607823bfee771c0ed06679af6770d21eda87838fb766dd578002ae035

See more details on using hashes here.

Provenance

The following attestation bundles were made for autodlctl-0.1.0.tar.gz:

Publisher: release.yml on zlh123123/autodlctl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autodlctl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autodlctl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for autodlctl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f02ced701bb23bba7b1b4e4dac7d82b574503c9e730a3d368a4fe145770c7da0
MD5 5d4427445afc261633d6455ed82aeaf6
BLAKE2b-256 47dcf741df1cdbf591c2a9dba7ae119cc71fe2c383a3d8c93e249b3293a2dbb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for autodlctl-0.1.0-py3-none-any.whl:

Publisher: release.yml on zlh123123/autodlctl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page