MLB recipes
Baseball lives under sdv.mlb, which spans three surfaces: the ESPN
cross-league wrappers (espnMlb*), the native MLB Stats API (mlb*,
host statsapi.mlb.com), and Baseball Savant / Statcast (mlbStatcast*,
host baseballsavant.mlb.com). All honor { parsed: true }.
ESPN scoreboard
import sdv from 'sportsdataverse';
const games = await sdv.mlb.espnMlbScoreboard({ parsed: true });
console.table(games);
MLB Stats API schedule (native)
statsapi.mlb.com's own schedule feed. Defaults to today; scope it with a
date (YYYY-MM-DD) or a season.
import sdv from 'sportsdataverse';
const schedule = await sdv.mlb.mlbSchedule({ parsed: true });
console.table(schedule);
Live and inline — statsapi.mlb.com's schedule, parsed to one row per game.
Add a date (YYYY-MM-DD) to scope it:
import sdv from 'sportsdataverse';
// scope to a single day
const opening = await sdv.mlb.mlbSchedule({ date: '2024-03-28', parsed: true });
console.table(opening);
Team roster (native)
team_id 147 is the Yankees in the Stats API.
import sdv from 'sportsdataverse';
const roster = await sdv.mlb.mlbTeamRoster({ team_id: 147, parsed: true });
console.table(roster);
Statcast leaderboards (Baseball Savant)
baseballsavant.mlb.com exposes ~40 Statcast leaderboards under mlbStatcast*.
Here's the bat-tracking board — bat speed, swing length, fast-swing rate. Scope
with a year.
import sdv from 'sportsdataverse';
const batTracking = await sdv.mlb.mlbStatcastLeaderboardBatTracking({
year: 2024,
parsed: true,
});
console.table(batTracking.slice(0, 10));
Statcast leaderboards stream CSV (not JSON), so the inline cell below shows
the raw response body — the package's mlbStatcast* parsers turn that CSV into
tidy rows in Node (the browser cell just surfaces it). Scope with a year:
Statcast pitch-by-pitch search
The date-chunked search pulls Statcast events. Scope it tightly (a date range, a team, a pitch type) so the result stays manageable.
import sdv from 'sportsdataverse';
const events = await sdv.mlb.mlbStatcastSearch({
season: 2024,
player_type: 'pitcher',
parsed: true,
});
console.table(events.slice(0, 10));
Full method + parameter tables: MLB reference (covers the ESPN, Stats API, and Statcast / Baseball Savant families).