Unofficial Python SDK for Westlake University AI Station
Project description
aistation
AI Station 的非官方 Python SDK 和 CLI。
仍然需要vpn解决内网环境
安装
pip install ai-station-sdk
基础安装现在已经包含 CLI 运行所需依赖。
如果你想要更好的验证码终端渲染能力(Pillow):
pip install "ai-station-sdk[cli]"
CLI
CLI 可以查询状态,也支持 task/env 的创建、等待和删除辅助操作。
aistation login # 交互式登录
# or
# export AISTATION_ACCOUNT=your_account
# export AISTATION_PASSWORD='your_password'
# aistation login
aistation status
aistation gpus
aistation task list
aistation env list
Python
import aistation as A
with A.AiStationClient() as client:
spec = A.TaskSpec.gpu_hold(
resource_group="8A100_80",
image="pytorch/pytorch:21.10-py3",
hours=2,
)
result = client.tasks.create_and_wait(spec)
task = result.unwrap()
pods = client.tasks.wait_pods(task)
print(task.id, len(pods))
如果你只想恢复本地 token、不做自动登录:
import aistation as A
client = A.AiStationClient(auth_mode=A.AuthMode.TOKEN_ONLY)
如果你想显式控制请求遇到过期 token 时是否自动重登:
import aistation as A
client = A.AiStationClient(reauth_policy=A.ReauthPolicy.IF_POSSIBLE)
异步用法:
import aistation as A
async with A.AsyncAiStationClient() as client:
spec = A.WorkPlatformSpec.notebook(
resource_group="DEV-POOL",
image="registry.example.invalid/ml/dev:latest",
)
wp = (await client.workplatforms.create(spec)).unwrap()
print((await client.workplatforms.jupyter_url(wp)).get("url"))
高层 async helper:
import aistation as A
from aistation import aio
async with A.AsyncAiStationClient() as client:
ctx = await aio.enumerate_form_context(client)
groups = await aio.recommend.suggest_groups(client, card_type_contains="A100")
print(len(ctx.images), len(groups))
创建类接口统一返回 OperationResult:
import aistation as A
with A.AiStationClient() as client:
result = client.tasks.create_and_wait(spec)
task = result.unwrap()
print(result.created, result.reused, result.waited, task.id)
client.tasks.stop(task) # 直接传 Task 对象
更多
- 示例见 docs/examples.md
- 性能/交互优化分析见 docs/sdk-ux-performance-optimization.md
- 收尾记录见 docs/cleanup-0.2.0.md
- async 实施记录见 docs/async-client-implementation.md
- License: MIT
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 ai_station_sdk-0.3.0.tar.gz.
File metadata
- Download URL: ai_station_sdk-0.3.0.tar.gz
- Upload date:
- Size: 200.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e951e4428d36f51c6a1a5c3a0328e93659258079f5f2324b581ca8b90eeedfc0
|
|
| MD5 |
48757125331eedb01eaed5c76a026406
|
|
| BLAKE2b-256 |
4c17a1f33384ae105e37ee61394128b2711b070d5a6070f8aa4250de9c1bf751
|
File details
Details for the file ai_station_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ai_station_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 115.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61bb76bebdabe12f16373a2d3a96e5104cfbe0bf52fc5f7428444b39e6566707
|
|
| MD5 |
5d6255fc13057eec21677828fefb36cb
|
|
| BLAKE2b-256 |
62c195cd423c87777f8e68dfb073ca655de5f2214b1823fce41d7b54ec56e6d7
|