Registry / http-networking / mlb-statsapi

mlb-statsapi

JSON →
library1.9.0pypypi✓ verified 84d ago

A Python wrapper for the MLB Stats API, providing easy access to MLB data including schedules, standings, player stats, and more. Version 1.9.0 is the latest stable release. Updates are frequent, with several releases per year.

pip install mlb-statsapi
INSTALL
IMPORT
SIG · MLB-STATSAPI
M
mlb-statsapi
http-networkingpythonv1.9.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

statsapi
import statsapi
from mlb_statsapi import ...
Package name uses hyphens, but import uses underscores implicitly. The top-level module is 'statsapi', not 'mlb_statsapi'.

Quick example of common operations: schedule, player lookup, and standings.

import statsapi # Get today's schedule schedule = statsapi.schedule() print(schedule) # Get player info player = statsapi.lookup_player('Mike Trout') print(player) # Get standings for a specific division standings = statsapi.standings_data(divisionId=200) print(standings.keys())
Debug
Known issues
gotchaThe module to import is 'statsapi', not 'mlb_statsapi'. The package name on PyPI is 'mlb-statsapi', but after installation, you use 'import statsapi'.
fix
Use 'import statsapi' in your code.
affects: all
gotchaThe schedule function may raise a KeyError if game data is missing (e.g., no team score or name). This is partially fixed in v1.6, but edge cases remain.
fix
Upgrade to v1.6.1+ or wrap in try/except.
affects: <1.6.1
breakingThe 'startDate' and 'endDate' parameters for stats endpoint were added in v1.8.1. Older versions do not support these parameters.
fix
Upgrade to v1.8.1+ if you need date filtering for stats.
affects: <1.8.1
deprecatedThe 'get()' method's 'params' parameter now defaults to empty dict (v1.8+). Previously it required explicit passing. Code relying on old default may break.
fix
Ensure you pass params as a dict or rely on new default.
affects: >=1.8
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mlb_statsapi'
Incorrect import path; using underscore instead of the correct module name 'statsapi'.
fix
Change import to 'import statsapi'.
KeyError: 'teams'
Schedule function expects certain keys in the API response; missing data for unplayed games or incomplete schedule.
fix
Check if game is complete before accessing team data, or upgrade to latest version.
AttributeError: module 'statsapi' has no attribute 'game_uniforms'
Attempting to use game_uniforms endpoint that was added in v1.9.0.
fix
Upgrade to mlb-statsapi>=1.9.0.
Upgrade
Version history
1.9.0latest on PyPI · released Apr 4, 2025
Audit
Dependencies
requestsrequiredHTTP library for API calls
Agent activity
4 hits · last 30 days
node
4
Resources
mlb-statsapi — pip install mlb-statsapi · libregistry