Getting Started
Prerequisites
You need a Rust toolchain (rustup recommended).
Linux additionally needs system libraries used by two transitive -sys crates:
| Package | Used by | Purpose |
|---|
pkg-config | build system | locate the libs below |
OpenSSL dev headers (libssl-dev / openssl-devel) | openssl-sys ← reqwest's native-tls | HTTPS to PKU services |
D-Bus dev headers (libdbus-1-dev / dbus-devel) | libdbus-sys ← keyring's Linux Secret Service backend | store/read IAAA credentials |
C toolchain (build-essential / gcc) | linker for the above | compile native code |
One-liners:
# Debian / Ubuntu
sudo apt install -y pkg-config libssl-dev libdbus-1-dev build-essential
# Fedora / RHEL
sudo dnf install -y pkg-config openssl-devel dbus-devel gcc
# Arch
sudo pacman -S --needed pkgconf openssl dbus base-devel
[!NOTE]
At runtime, info-auth store on Linux talks to a running Secret Service
(GNOME Keyring, KWallet, KeePassXC, …). On a headless server without one,
fall back to env vars: export PKU_USERNAME=… PKU_PASSWORD=….
macOS and Windows need no extra system packages — native-tls uses
Security framework / SChannel and keyring uses Keychain / Credential Manager.
Just install the Rust toolchain.
Install
cargo install pku-cli --locked
One command installs the unified pku binary with access to all tools:
pku treehole login -p # Login to treehole
pku course courses --all # List all courses
pku card info # Campus card balance
pku elective show # View course selections
pku auth store # Store IAAA credentials
pku spider search "北大" # Search WeChat articles
[!TIP]
You can also install tools individually if you only need specific ones:
cargo install pku-treehole pku-course pku-campuscard pku-elective pku-auth pkuinfo-spider
First-time Setup
1. Store your IAAA credentials once (encrypted in your OS keychain):
info-auth store
2. Login to any service — credentials resolve automatically:
treehole login -p
course login -p
campuscard login -p
elective login -p
[!NOTE]
Passwords are never exposed in CLI arguments, environment variables, or logs.
The info-auth store command uses interactive input and stores credentials in the
OS keychain (macOS Keychain / GNOME Keyring / Windows Credential Manager).
Tools
Treehole — 北大树洞
Anonymous forum client with full read/write support.
treehole list # Browse latest posts
treehole search "关键词" # Full-text search
treehole show 12345 # View post + replies
treehole post -t "Hello world" # Create a post
treehole score # View your grades
treehole schedule # This week's schedule
Course — 教学网 (Blackboard Learn)
Course management, assignments, lecture recordings, and tools for teaching assistants.
course courses --all # List all courses
course assignments # Pending assignments
course videos # Lecture recordings
course submit # Submit homework (interactive)
course browse # Interactive course browser
course ta --help # TA tools: post files, create assignments, grade (writes need --yes)
Campuscard — 校园卡
Campus card balance, payments, transaction history.
campuscard info # Card info & balance
campuscard pay # Show payment QR code
campuscard bills --month 2026-03 # Transaction history
campuscard stats # Monthly spending breakdown
campuscard recharge -a 100 # Top up 100 yuan
Elective — 选课网
Course selection with automated retry and CAPTCHA handling.
elective show # Current selections
elective list # Available courses
elective set # Pick target courses (interactive)
elective launch -t 15 # Auto-select loop, 15s interval
Disk — 北大网盘
Browse and download PKU Netdisk files (read-only): personal, shared and department libraries.