Skip to main content

ustc-sdk

中国科大校园系统的异步 Python SDK,要求 Python 3.11+。

提供显式账号、独立会话的统一认证、第二课堂、教务、学习空间和体育场馆客户端。 公开数据模型使用 Pydantic,支持 JSON 序列化与 JSON Schema。

安装

uv add ustc-sdk

读取第二课堂活动

import asyncio
import os

from ustc_sdk import CASClient, YoungClient


async def main():
    async with CASClient(os.environ["USTC_USERNAME"], os.environ["USTC_PASSWORD"]) as cas:
        async with YoungClient(cas) as young:
            for activity in await young.list_activities(limit=5):
                print(activity.model_dump_json())


asyncio.run(main())

账号配置由应用负责;客户端不会自动查找其他工具的配置或共享全局账号状态。 CAS Cookie 保留原始域名、路径和 Secure 属性;各校园系统分别持有自己的应用会话。 二课 list_activities(limit=0) 不请求活动页,负数上限抛出 ValueError。 分页按实际返回的记录数判断是否完整,兼容数字字符串总数;无法确认总数时抛出 ProtocolError,避免把部分列表当作完整结果。 全量读取请求每页 100 条,按服务端实际返回数量继续分页;系列展开每批最多 4 个并发只读请求,并保持活动顺序。expand_series=True 的关键字搜索会匹配子活动名称。

模块

  • ustc_sdk.auth:CAS 认证与服务票据。
  • ustc_sdk.young:第二课堂列表、详情、已参与活动、报名与取消。
  • ustc_sdk.eams:课表、成绩、选退课与课程调整。
  • ustc_sdk.spaces:学习空间房间、成员、预约查询及写操作。
  • ustc_sdk.venue_booking:体育场馆查询与已有订单操作;创建预约所需的小程序设备验证字段未提供。

业务流程、存储和定时扫描由独立的 ustc-tools 包提供。 学习空间上游使用明文 HTTP;CAS 密码仅提交到 HTTPS 认证站点。 写操作出现 SubmissionUnknown 时需先查询服务器状态,不能直接重发。 二课报名/取消收到 HTTP 5xx、非 JSON 或缺少明确布尔结果时也会抛出 SubmissionUnknown;服务器明确返回失败时仍提供结构化失败结果。 学习空间的用户输入时间严格为 HH:MM,不会把带秒的输入静默截断。

来源与许可

MIT。认证、教务、二课与体育协议基于 pyustc v1.2.1, 学习空间协议基于 xtcli 固定快照。 原始许可和来源说明随包附带。

源码与完整文档

Metadata

Release files for ustc-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ustc-sdk 0.2.0
File Size Uploaded Provenance Actions
ustc_sdk-0.2.0.tar.gz 36.2 kB Without provenance Details for ustc_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ustc-sdk 0.2.0
File Interpreter ABI Platform Actions
ustc_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for ustc_sdk-0.2.0-py3-none-any.whl

Total release size: 82.7 kB

Release files / ustc_sdk-0.2.0.tar.gz

Download URL ustc_sdk-0.2.0.tar.gz
Size 36.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d22966a0eb452d1026e6eaa97473b9b941d9ade3c946743e1002ce54c220639e
BLAKE2b-256 checksum
How to use checksums
f7a12b209b7b7607e279e2c3ef637417f2fcc44d77e1cc5617012abefafd63de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ustc_sdk-0.2.0-py3-none-any.whl

Download URL ustc_sdk-0.2.0-py3-none-any.whl
Size 46.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba3f7ad77cb27a36fbd9898f235e90fb413a3419ded6b8761ccef0db751eb261
BLAKE2b-256 checksum
How to use checksums
c27602e8227db80953904d6b6443d5c67e70df764c5cad89f5c0673b5eac9c31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ustc-sdk 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page