A Python wrapper for the MLB Stats API that provides easy access to baseball statistics, game data, and more.
pip install MLB-StatsAPIimport statsapi
# Get today's games
games = statsapi.schedule()
# Get box score for a specific game
boxscore = statsapi.boxscore(718757)
# Get player statistics
player_stats = statsapi.player_stats(592450)
# Get current standings
standings = statsapi.standings()- Game schedules and results
- Box scores and game details
- Player statistics and information
- Team standings and leaders
- League leaders and rankings
- Team rosters
- And much more!
# Get games for a specific date
games = statsapi.schedule(date='2024-03-28')
# Get games for a date range
games = statsapi.schedule(start_date='2024-03-28', end_date='2024-03-30')
# Get games for a specific team
games = statsapi.schedule(team='141') # 141 is the team ID for the Toronto Blue Jays# Look up a player
player = statsapi.lookup_player('Mike Trout')
# Look up a team
team = statsapi.lookup_team('Blue Jays')# Get team leaders
leaders = statsapi.team_leaders(141, ['homeRuns', 'rbi', 'avg'])
# Get league leaders
leaders = statsapi.league_leaders(['homeRuns', 'rbi', 'avg'])For detailed documentation and API reference, visit our Wiki.
Contributions are welcome! Please feel free to submit a Pull Request.
Found a bug or have a feature request? Please open an issue.
This package and its author are not affiliated with MLB or any MLB team. This API wrapper interfaces with MLB's Stats API. Use of MLB data is subject to the notice posted at http://gdx.mlb.com/components/copyright.txt.
This project is licensed under the terms of the license included in the repository.