mlb-api
The Rust MLB API Wrapper
This project and its author are not affiliated with MLB or any MLB team. This crate wraps the existing MLB Stats API, which is subject to the notice posted at http://gdx.mlb.com/components/copyright.txt.
Usage
Endpoints are most commonly used using their module's builder functions.
use SportId;
use RequestUrlBuilderExt;
use ;
let response: ScheduleResponse = request
.sport_id
.build_and_get
.await?;
let : = response.dates.try_into?;
Play Streams are the recommended way to process live games
use PlayStream;
let game: ScheduleGame = ...;
new.run.await?;
Use single_stat! for simple stats requests and make your own hydrations for more complicated requests
use single_stat;
use ;
let season_hitting = single_stat!.await?;
let sabermetrics_pitching = single_stat!.await?;
person_hydrations!
}
let response: PeopleResponse = .await?;
Endpoints
This API contains wrappers / bindings for all known public MLB API endpoints (unless incomplete), the table of which can be seen below. Additional information can be found at https://github.com/toddrob99/MLB-StatsAPI/wiki/Endpoints (thanks Todd Roberts)
Stars hightlight the most popular and used endpoints
| Endpoint | Description |
|---|---|
attendance |
Team attendance data by season |
awards |
List of all awards, Cy Young, MVP, etc. |
conference |
Conferences, like divisions but not |
division |
Names, has a wildcard or not, playoff teams |
draft |
Draft rounds, players, etc. |
live_feed ⭐ |
boxscore, linescore, plays, and misc |
diff_patch |
JSON diff patch for live feed |
timestamps |
List of timestamps for game plays & play events |
changes |
Games that underwent scheduling changes (?) |
context_metrics |
Various metrics for game plays & play events |
win_probability |
Win Probability calculations for games |
boxscore |
Boxscore summary for game, includes stats |
content |
Editorial content regarding games |
linescore |
Linescore for games |
plays |
Play by Play Data on a game |
uniforms |
Game Uniforms |
pace |
Average game durations and league stat totals |
home_run_derby |
Home Run Derby stats |
league |
League data, AL, NL, divisions contained, etc. |
all_star |
ASG data |
person ⭐ |
A person, lots of data here |
free_agents |
Free agents in any given year |
person_stats |
Player stats for a single game |
jobs |
List of all people with a job, ex: scorer, ump |
jobs::umpire |
List of all umpires |
jobs::datacasters |
List of all datacasters |
jobs::official_scorers |
List of all official scorers |
schedule ⭐ |
All games played within a certain date range |
schedule::tied |
All games that ended tied (?) |
schedule::postseason |
Postseason schedule |
schedule::postseason::series |
Postseason series schedule |
season |
Date ranges for season states: reg, post, spring |
sport |
List of sports, MLB, AAA, AA, A+, etc. |
players ⭐ |
List of all players in a sport and season |
standings |
Standings information for teams |
stats |
Stats data |
stats::leaders |
League leaders in specific stats |
team ⭐ |
Team data |
team::history |
History of a team, such as Brooklyn & LA Dodgers |
team::stats |
Stats for a team |
team::affiliates |
Minor league affiliate teams |
team::alumni |
Alumni for a team |
team::coaches |
List of coaches on a team |
team::personnel |
Personnel on a team |
team::leaders |
Stat leaders per team |
team::roster |
Roster players on a team |
team::uniforms |
Uniforms a team wears |
transactions |
Trades, IL moves, etc. |
venue |
Yankee Stadium, Dodger Stadium, Fenway Park, etc. |
meta |
Metadata endpoints, typically cached or enums |
Usage & Appendix
- This API defaults to using
reqwestandtokiofor non-blocking IO, there is aureqfeature to switch toureqandparking_lotfor blocking IO. - Use
PlayStreamfor obtaining live updates on games. - Use
single_stat!for simple stat requests rather than making [person_hydrations!] andPersonRequestyourself. - Use
as_complete_or_requestand the numerouscrate::*_hydrations!items to obtain additional information in requests, try to minimize request quantity. - The
precachefunction allows caching commonly requested values before usage to makeas_complete_or_requestfaster to use. - Supply
SeasonIds to requests to not have them break when the year changes.
License: MIT