You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
v0.1.6
FIX: Required params for game_diff endpoint don't match query_params (case sensitivity) #31
NEW: Added batter 2b, 3b, hr, sb to box score data (but not formatted box score) and refactored box score code (thanks @rogerhcheng)
NEW: Wiki added to GitHub, documentation removed from source code including README
NEW: GitHub Sponsors button added to repository
MLB-StatsAPI is listed on the [Python Package Index](https://pypi.org/project/MLB-StatsAPI/),
15
-
and the preferred installation method is pip for all platforms.
16
-
If you install manually, be sure to also install requests.
17
-
18
-
```pip install MLB-StatsAPI```
19
-
20
-
## Available Functions
21
-
22
-
*`statsapi.get()` - make calls directly to MLB StatsAPI endpoints; supports the most flexibility in request parameters, and returns raw json data
23
-
24
-
*`statsapi.meta()` - retrieve available values from StatsAPI for use in other queries, or look up descriptions for values found in API results
25
-
26
-
*`statsapi.notes()` - retrieve notes for a given endpoint, including a list of required parameters, as well as hints for some endpoints
27
-
28
-
*`statsapi.lookup_player()` - get a list of player data based on first, last, or full name, jersey number, current team Id, position, etc.
29
-
30
-
*`statsapi.lookup_team()` - get a list of teams' info based on the team name, city, abbreviation, or file code
31
-
32
-
*`statsapi.schedule()` - retrieve a list of games on a given date/range and/or team/opponent
33
-
34
-
*`statsapi.boxscore()` - generate a formatted boxscore for a given game
35
-
36
-
*`statsapi.boxscore_data()` - generate a dict containing boxscore data for a given game
37
-
38
-
*`statsapi.linescore()` - generate a formatted linescore for a given game
39
-
40
-
*`statsapi.roster()` - generate a formatted list of players on a team's roster
41
-
42
-
*`statsapi.standings()` - generate a formatted list of standings for a given league/date
43
-
44
-
*`statsapi.standings_data()` - returns a python list of standings data for a given league/date
45
-
46
-
*`statsapi.team_leaders()` - generate a formatted list of a team's leaders for a given stat
47
-
48
-
*`statsapi.team_leader_data()` - returns a python list of a team's leader data for a given stat
49
-
50
-
*`statsapi.league_leaders()` - generate a formatted list of stat leaders for current or specified season
51
-
52
-
*`statsapi.league_leader_data()` - returns python list of stat leader data for current or specified season
53
-
54
-
*`statsapi.player_stats()` - generate a formatted list of a player's career or season stats
55
-
56
-
*`statsapi.player_stat_data()` - returns a python dict of a player's career or season stats, along with some biographical information
57
-
58
-
*`statsapi.last_game()` - get the game id for the given team's most recent game
59
-
60
-
*`statsapi.next_game()` - get the game id for the given team's next game
61
-
62
-
*`statsapi.game_highlights()` - generate a formatted list of highlights with video links for a given game
63
-
64
-
*`statsapi.game_highlight_data()` - returns a python list of highlight data, including video links, for a given game
65
-
66
-
*`statsapi.game_pace()` - generate a formatted list of pace of game information for a given season (back to 1999)
67
-
68
-
*`statsapi.game_pace_data()` - returns a python dict of pace of game information for a given season (back to 1999)
69
-
70
-
*`statsapi.game_scoring_plays()` - generate a formatted list of scoring plays for a given game
71
-
72
-
*`statsapi.game_scoring_play_data()` - returns a python dict of scoring play data for a given game
73
-
74
-
## Example Use
75
-
76
-
### Print the number of games won by the Oakland Athletics in 2018
77
-
78
-
Use `statsapi.schedule()` to retrieve all A's games for 2018,
79
-
and use `sum()` to count records in the resultset where the A's were the winning_team.
80
-
81
-
```
82
-
print('The A\'s won %s games in 2018.' % sum(1 for x in statsapi.schedule(team=133,start_date='01/01/2018',end_date='12/31/2018') if x.get('winning_team','')=='Oakland Athletics'))
83
-
```
84
-
85
-
### Print the linescore for all games the Phillies won in July 2008
86
-
87
-
Use `statsapi.schedule()` to retrieve all games for July 2018,
88
-
run the resulting dict through a list comprehension
89
-
to iterate over the records where the Phillies are the winning team,
90
-
and feed the `game_id` into `statsapi_linescore()`.
91
-
92
-
```
93
-
for x in [y for y in statsapi.schedule(team=143,start_date='07/01/2008',end_date='07/31/2008') if y.get('winning_team','')=='Philadelphia Phillies']:
### Print the Phillies 40-man Roster on opening day of the 2018 season
98
-
99
-
Use `statsapi.get('season')` to retrieve the dates for the 2018 season,
100
-
feed the opening day date into `statsapi.roster()`.
101
-
102
-
```
103
-
print('Phillies 40-man roster on opening day of the 2018 season:\n%s' % statsapi.roster(143,'40Man',date=statsapi.get('season',{'seasonId':2018,'sportId':1})['seasons'][0]['regularSeasonStartDate']))
104
-
```
105
-
106
-
### Print the boxscore and linescore from the A's most recent game (which may be in progress or may not have started yet based on MLB response to 'last game' request)
107
-
108
-
Use `statsapi.last_game()` to retrieve the most recent A's game
109
-
and feed the gamePk into `statsapi.boxscore()` and `statsapi.linescore()`.
110
-
111
-
```
112
-
most_recent_game_id = statsapi.last_game(133)
113
-
print(statsapi.boxscore(most_recent_game_id))
114
-
print(statsapi.linescore(most_recent_game_id))
115
-
```
116
-
117
-
### Find the team with the longest name
118
-
119
-
Use `statsapi.get('teams')` to retrieve all active team names,
120
-
then feed into max() to find the longest value and its length
121
-
122
-
```
123
-
longest_team_name = max([x['name'] for x in statsapi.get('teams',{'sportIds':1,'activeStatus':'Yes','fields':'teams,name'})['teams']],key=len)
124
-
print('The team with the longest name is %s, at %s characters.' % (longest_team_name, len(longest_team_name)))
125
-
```
126
-
127
-
### Print the standings from July 4, 2018
128
-
129
-
Use `statsapi.standings()` with the `date` parameters
130
-
131
-
```
132
-
print(statsapi.standings(date='07/04/2018'))
133
-
```
134
-
135
-
### Print the top 5 team leaders in walks for the 2008 Phillies
use `statsapi.get()` to call the sports_players endpoint for the 2008 World Series,
154
-
lookup Chase Utley's person id from the results, and pass it into `statsapi.player_stats()`
155
-
using `type='hitting'` and `group='career'`
156
-
157
-
```
158
-
print( statsapi.player_stats(next(x['id'] for x in statsapi.get('sports_players',{'season':2008,'gameType':'W'})['people'] if x['fullName']=='Chase Utley'), 'hitting', 'career') )
159
-
```
160
-
161
-
### Print a list of scoring plays from the 4/28/2019 Marlins @ Phillies game
0 commit comments