Skip to content

Repository files navigation

Important

📢📢📢

这是全网唯一一个自动处理验证码的新版教务系统 SDK, 并且本项目有完善的 type hints.

本项目理论上支持教务系统所有功能,兼容所有学校 :P

使用过程中如有遇到本 SDK 暂不支持的功能,请使用 proxy_request

Downloads codecov python3 license stars forks PyPI Version

新版正方系统 Python SDK。(支持自动识别、处理滑块验证码与常规验证码,如果觉得还不错,给个小星星趴~⭐)

在线文档

Roadmap

支持的登录/验证码方式

  • 帐号密码登录
  • 滑块验证码登录
  • 图形验证码登录
  • cookie 登录(用于扫码登录、OIDC 等场景)

测试环境

  • 3.8 <= Python <= 3.13
  • 默认验证码识别方式(推理): CPU

Usage

# (推荐)
$ uv add school-sdk
# or
$ pip install school-sdk
# or
$ pip install zf-school-sdk

⚠️ v1.9.0 起 PyTorch 不再是必装依赖

只有你的学校启用了图形验证码(captcha_type 为 kap 开头)才需要 PyTorch,请额外安装:

$ uv add school-sdk[kaptcha]
# or
$ pip install school-sdk[kaptcha]

无验证码与滑块验证码(captcha_type="captcha")不需要额外依赖。

[kaptcha] 会拉取数百 MB 的 PyTorch,如果机器内存/磁盘紧张,可加 --no-cache-dir 安装,e.g. pip install --no-cache-dir school-sdk[kaptcha]

from school_sdk import SchoolClient
from school_sdk.client import UserClient

# 先实例化一个学校,再实例化用户
school = SchoolClient("172.16.254.1")
user:UserClient = school.user_login("2018xxxxx", "xxxxxxxx")

# 获取 2020 学年第二学期的课程
course = user.get_schedule(year=2020, term=2)
print(course)

使用示例参见 examples

使用 uv(推荐用于本地开发)

# 1) 同步依赖并创建虚拟环境
$ uv sync

# 2) 进入虚拟环境(可选)
$ source .venv/bin/activate

# 3) 运行示例
$ uv run python examples/base_sample.py

如果只需要运行时依赖,可使用:uv sync --no-dev

如需本地调试图形验证码识别:uv sync --extra kaptcha

建议安装 pre-commit 钩子,提交前自动运行离线测试与基础检查:uv run pre-commit install

Api Function

Api Description Argument
user_login 登陆函数 account, password
get_schedule 课表查询 year, term
get_score 成绩查询 year, term
get_info 获取个人信息 None
refresh_info 刷新个人信息 None
check_session 检查session并其失效后重登录 None
proxy_request 补充 sdk 未实现的业务功能,以支持各种登录后的教务系统操作 method, url_or_endpoint, **kwargs

School-SDK Options

Option Default Description
host 不存在默认值 教务系统地址(必填)
port 80 端口号
ssl False 教务系统是否使用https
name None 学校名称
exist_verify False 是否存在验证码
captcha_type captcha 验证码类型,枚举类型(kaptcha: 常规图形验证码,需安装 school-sdk[kaptcha] 或 captcha: 滑块)
retry 10 登录重试次数
lan_host None 内网地址(暂不可用)
lan_port 80 内网地址端口(暂不可用)
timeout 10 全局请求延时
url_endpoints None 地址配置

相关项目

帮教务系统做负载均衡:https://github.com/FarmerChillax/school-load-balance

(如果你们学校教务系统抢课经常崩溃,可以考虑看看这个 repo)

Thanks to all of our contributors! 🎉

Repo contributors

About

👋 校园教务系统爬虫接口,新版正方教务系统 SDK for Python(新正方教务系统API),支持多种登录方式,自动识别并处理验证码(包含两种验证码的处理)

Topics

Resources

Stars

125 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages