PyMLB StatsAPI Documentation๏ƒ

A clean, Pythonic wrapper for MLB Stats API endpoints with automatic schema-driven parameter validation.

Tests codecov PyPI Python License

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๏ƒ

Additional Information

Indices and tables๏ƒ