PyMLB StatsAPI Documentation๏
A clean, Pythonic wrapper for MLB Stats API endpoints with automatic schema-driven parameter validation.
Quick Start๏
Installation๏
# With pip
pip install pymlb-statsapi
# With uv (recommended)
uv add pymlb-statsapi
Basic Usage๏
from pymlb_statsapi import api
# Get schedule (clean parameter passing!)
response = api.Schedule.schedule(sportId=1, date="2025-06-01")
data = response.json()
# Get live game data
response = api.Game.liveGameV1(game_pk="747175", timecode="20241027_000000")
data = response.json()
# Save response to file
result = response.gzip(prefix="mlb-data")
Key Features๏
๐ฏ Clean API: Parameters are intelligently routed to path or query params based on the schema configuration
๐ Schema-driven: All endpoints and methods generated from JSON schemas (sourced from https://beta-statsapi.mlb.com/docs/)
โ Type-safe: Automatic parameter validation from API schemas
๐ Dynamic: Zero hardcoded models - updates via schema changes only
๐งช Well-tested: Comprehensive unit tests with pytest and BDD test suite with stub capture/replay
๐ Explore the API๏
The Schema Reference is the heart of this library - browse 21 MLB Stats API endpoints with:
Detailed parameter documentation for every method
Working Python code examples
Schema introspection capabilities
Clear marking of functional vs non-functional endpoints
โก๏ธ Start here: Schema Reference
Contents๏
๐ Schema Reference (Start Here!)
User Guide
API Reference
Additional Information