Skip to main content

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);

Open in playground ▶

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:

Loading live cell…

Open in playground ▶

import sdv from 'sportsdataverse';

// scope to a single day
const opening = await sdv.mlb.mlbSchedule({ date: '2024-03-28', parsed: true });
console.table(opening);

Open in playground ▶

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);

Open in playground ▶

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:

Loading live cell…

Open in playground ▶

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));
tip

Full method + parameter tables: MLB reference (covers the ESPN, Stats API, and Statcast / Baseball Savant families).