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

该命令会打开 AutoDL 控制台,优先使用本机 Chrome 渠道,并使用 ~/.config/autodlctl/auth-profile 作为持久浏览器配置;如果系统中未安装 Chrome,则自动回退到 Playwright 自带的 Chromium。命令在确认登录成功后会尽快保存登录态并退出;--pause-seconds 表示最长等待时间,不会在超时前提前终止。默认将登录态保存到 .autodl/storage_state.json

如果验证码持续失败,建议保持相同的 --profile-dir 继续重试,避免频繁删除该目录;如需重新初始化登录环境,可删除该目录后重新登录。

2. 查询实例

autodlctl list

在已按默认路径保存登录态的情况下,可直接运行 autodlctl list;程序将默认读取 .autodl/storage_state.json

按条件筛选:

autodlctl list \
  --gpu-model 4090 \
  --min-gpu-free 1 \
  --sort-by rentable_until

3. 查看详情

autodlctl detail \
  --instance "你的实例名称或实例 ID"

detail 默认读取 .autodl/storage_state.json,一般不需要显式传 --storage-state;如需改成其他路径,再手动指定即可。

4. 开机 / 关机

startstop 也默认读取 .autodl/storage_state.json,通常直接传实例名或实例 ID 就可以。

autodlctl start \
  --instance "你的实例名称或实例 ID"
autodlctl stop \
  --instance "你的实例名称或实例 ID"

无卡模式开机:

autodlctl start \
  --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.2.tar.gz (30.1 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.2-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for autodlctl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0caedfbe30ed88389c597f6be73809cd72248a816042fe391c65c5e826584008
MD5 dd781689647a96bc721d4b04a35199f7
BLAKE2b-256 8da4f8787734c776ff8dcb5b0fef49482467b23a724fbc62df453ac68204aec1

See more details on using hashes here.

Provenance

The following attestation bundles were made for autodlctl-0.1.2.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.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for autodlctl-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 effc0b69aeb6a12a83d1b56b149fc7ba28d695466402b9f6424f877c8b26b815
MD5 5ed23bae491a77f26b221f8d97301b13
BLAKE2b-256 a54df902a095ceae4e6f4e1ce1935297c83eb04512e4a43c0ad33ba39da46281

See more details on using hashes here.

Provenance

The following attestation bundles were made for autodlctl-0.1.2-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