TrainingPeaks Skill
CLI access to the TrainingPeaks internal API. Pure Python stdlib — no pip dependencies.
Setup: Getting Your Auth Cookie
- 1. Log in to TrainingPeaks in your browser
- Open DevTools → Application → Cookies → INLINECODE0
- Find the cookie named INLINECODE1
- Copy its value (long encoded string)
Then authenticate:
CODEBLOCK0
Or set the environment variable (useful for CI/scripts):
CODEBLOCK1
Credentials are stored in ~/.trainingpeaks/ with 0600 permissions.
Commands
auth <cookie> — Authenticate
Store and validate a Production_tpAuth cookie. Exchanges it for a Bearer token and caches the athlete ID.
CODEBLOCK2
auth-status — Check Authentication
CODEBLOCK3
profile [--json] — Athlete Profile
CODEBLOCK4
workouts <start> <end> [--filter all|planned|completed] [--json]
List workouts in a date range (max 90 days).
CODEBLOCK5
Output columns: Date, Title, Sport, Status (✓/○), Planned duration, Actual duration, TSS, Distance.
workout <id> [--json] — Workout Detail
Get full details for a single workout including description, coach comments, and all metrics.
CODEBLOCK6
fitness [--days 90] [--json] — CTL/ATL/TSB
Get fitness (CTL), fatigue (ATL), and form (TSB) data.
CODEBLOCK7
Shows a summary with current CTL/ATL/TSB and status interpretation, plus a 14-day daily table.
peaks <sport> <pr_type> [--days 3650] [--json] — Personal Records
Get ranked personal records by sport and metric.
CODEBLOCK8
Valid PR types:
| Sport | Types |
|---|
| Bike | INLINECODE12 , power1min, power5min, power10min, power20min, power60min, power90min, hR5sec, hR1min, hR5min, hR10min, hR20min, hR60min, INLINECODE25 |
| Run |
hR5sec–
hR90min,
speed400Meter,
speed800Meter,
speed1K,
speed1Mi,
speed5K,
speed5Mi,
speed10K,
speed10Mi,
speedHalfMarathon,
speedMarathon,
speed50K |
Token Management
- - Bearer tokens are cached in INLINECODE39
- Tokens expire in ~1 hour; auto-refreshed from stored cookie
- Cookie lasts weeks; stored in INLINECODE40
- If the cookie expires, you'll get a clear error to re-authenticate
File Locations
| File | Purpose |
|---|
| INLINECODE41 | Stored Production_tpAuth cookie |
| INLINECODE43 |
Cached OAuth Bearer token + expiry |
|
~/.trainingpeaks/config.json | Cached athlete ID and account info |
Notes
- - All dates use
YYYY-MM-DD format - Maximum workout query range: 90 days
- Rate limiting: 150ms minimum between API requests
- INLINECODE46 environment variable overrides stored cookie
- Default output is human-readable;
--json gives raw API responses
TrainingPeaks 技能
通过CLI访问TrainingPeaks内部API。纯Python标准库实现——无需pip依赖。
设置:获取认证Cookie
- 1. 在浏览器中登录TrainingPeaks
- 打开开发者工具 → 应用 → Cookie → app.trainingpeaks.com
- 找到名为ProductiontpAuth的Cookie
- 复制其值(长编码字符串)
然后进行认证:
bash
python3 scripts/tp.py auth <粘贴cookie值_此处>
或设置环境变量(适用于CI/脚本):
bash
export TPAUTHCOOKIE=
凭据存储在~/.trainingpeaks/目录下,权限为0600。
命令
auth — 认证
存储并验证Production_tpAuth Cookie。将其交换为Bearer令牌并缓存运动员ID。
bash
python3 scripts/tp.py auth eyJhbGci...
✓ 认证成功!
账户:user@example.com
运动员ID:12345
令牌过期时间:60分钟
auth-status — 检查认证状态
bash
python3 scripts/tp.py auth-status
Cookie:已存储(文件)
令牌:有效(剩余42分钟)
运动员ID:12345
✓ 就绪
profile [--json] — 运动员资料
bash
python3 scripts/tp.py profile
资料
════════════════════════════════════════
姓名: Ruben示例
邮箱: ruben@example.com
运动员ID: 12345
账户: 高级版
自行车FTP:280 W
workouts <开始日期> <结束日期> [--filter all|planned|completed] [--json]
列出日期范围内的训练(最多90天)。
bash
本周所有训练
python3 scripts/tp.py workouts 2026-01-26 2026-02-01
仅已完成训练
python3 scripts/tp.py workouts 2026-01-01 2026-01-31 --filter completed
用于脚本处理的原始JSON
python3 scripts/tp.py workouts 2026-01-26 2026-02-01 --json
输出列:日期、标题、运动类型、状态(✓/○)、计划时长、实际时长、TSS、距离。
workout [--json] — 训练详情
获取单个训练的完整详情,包括描述、教练评论和所有指标。
bash
python3 scripts/tp.py workout 123456789
训练:节奏间歇 3x10分钟
══════════════════════════════════════════════════
日期: 2026-01-28
运动类型: 自行车
状态: 已完成 ✓
...
fitness [--days 90] [--json] — CTL/ATL/TSB
获取体能(CTL)、疲劳(ATL)和状态(TSB)数据。
bash
最近90天(默认)
python3 scripts/tp.py fitness
整个赛季
python3 scripts/tp.py fitness --days 365
用于图表的JSON
python3 scripts/tp.py fitness --json
显示当前CTL/ATL/TSB摘要及状态解读,以及14天每日表格。
peaks <运动类型> [--days 3650] [--json] — 个人纪录
按运动类型和指标获取排名个人纪录。
bash
最佳20分钟功率(历史所有)
python3 scripts/tp.py peaks Bike power20min
去年5公里跑步PR
python3 scripts/tp.py peaks Run speed5K --days 365
5秒最大功率
python3 scripts/tp.py peaks Bike power5sec
有效的PR类型:
| 运动类型 | 类型 |
|---|
| 自行车 | power5sec、power1min、power5min、power10min、power20min、power60min、power90min、hR5sec、hR1min、hR5min、hR10min、hR20min、hR60min、hR90min |
| 跑步 |
hR5sec–hR90min、speed400Meter、speed800Meter、speed1K、speed1Mi、speed5K、speed5Mi、speed10K、speed10Mi、speedHalfMarathon、speedMarathon、speed50K |
令牌管理
- - Bearer令牌缓存在~/.trainingpeaks/token.json
- 令牌约1小时过期;从存储的Cookie自动刷新
- Cookie有效期数周;存储在~/.trainingpeaks/cookie
- 如果Cookie过期,会收到明确的重新认证错误提示
文件位置
| 文件 | 用途 |
|---|
| ~/.trainingpeaks/cookie | 存储的Production_tpAuth Cookie |
| ~/.trainingpeaks/token.json |
缓存的OAuth Bearer令牌及过期时间 |
| ~/.trainingpeaks/config.json | 缓存的运动员ID和账户信息 |
注意事项
- - 所有日期使用YYYY-MM-DD格式
- 训练查询最大范围:90天
- 速率限制:API请求间隔至少150毫秒
- TPAUTHCOOKIE环境变量会覆盖存储的Cookie
- 默认输出为人类可读格式;--json返回原始API响应