# MLB Play-by-Play — Every Pitch Since 1915 (`sourcerow/mlb-play-by-play`) Actor

Every pitch and every event of Major League Baseball since 1915 — batter, pitcher, count, pitch sequence and the raw Retrosheet event notation, one row per play, licensed for commercial use.

- **URL**: https://apify.com/sourcerow/mlb-play-by-play.md
- **Developed by:** [SourceRow](https://apify.com/sourcerow) (community)
- **Categories:**
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.20 / 1,000 plays

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

Every pitch and every event of Major League Baseball, one row per play. Batter,
pitcher, the count, the pitch-by-pitch sequence and the event itself, from 1915
to the last completed season.

### What it does

Retrosheet publishes play-by-play as event files in its own notation, one line
per play, with the pitch sequence and the outcome encoded as strings that were
designed for compactness rather than reading.

This Actor parses a season into one row per play with 41 fields: who was at bat,
who was pitching, the count, the pitch sequence, the raw Retrosheet event code,
and a decoded outcome.

### What you get

41 fields per row, including `date`, `game_id`, `inning`, `half`,
`batting_team`, `batter_id`, `pitcher_id`, `balls`, `strikes`,
`pitch_sequence`, `play`, `outcome`, `is_plate_appearance`, `is_out`, `is_hit`,
`bases`, `modifiers`, `baserunning`, `count_known`,
`pitches_continue_next_row`, the park and game conditions, and the provenance
fields.

The table view shows 15 of them; all 41 are in the JSON, CSV and Excel
downloads.

### Input

| Field | Meaning |
|---|---|
| `fromSeason` | First season to include. |
| `toSeason` | Last season. |
| `teams` | Retrosheet team codes. Empty means all. |
| `maxPlays` | Stop after this many. `0` removes the cap. |

```json
{
  "fromSeason": 2024,
  "toSeason": 2024,
  "maxPlays": 1000
}
```

### Sample output

One record, trimmed to the fields shown in the table view:

```json
{
  "date": "2024-04-05",
  "game_id": "ANA202404050",
  "inning": 1,
  "half": "top",
  "batting_team": "BOS",
  "batter_id": "duraj001",
  "pitcher_id": "canng001",
  "balls": 0,
  "strikes": 0,
  "pitch_sequence": "X",
  "play": "6/P78S",
  "outcome": "fielded_out",
  "is_plate_appearance": true,
  "pitches_continue_next_row": false,
  "issues": ""
}
```

### Pricing

| Event | Per 1,000 | Notes |
|---|---|---|
| Play | $0.20 | One charge per play returned |

One season is about $50. There is no start fee and no per-row dataset fee.

### What it does not do

**Pitch counts double if you sum naively.** Retrosheet writes a `NP` (no play)
row when a substitution interrupts an at-bat, and repeats the pitch sequence on
the next row. `pitches_continue_next_row` marks those, and `issues` reports
`pitches_repeated_in_next_row`. Filter on `is_plate_appearance` instead, or
exclude the flagged rows.

**No count before 1988.** `count_known` is false for most earlier games. The
plays are recorded; the ball-strike count was not.

**No pitch velocity, spin or location.** Retrosheet is an event record, not
tracking data. For pitch physics, a different source is needed.

**`play` is Retrosheet notation.** `outcome` decodes the common cases. The raw
code is kept because the notation carries detail no decoding preserves.

**Volume.** One season is roughly 190,000 plays. Ten seasons is two and a half
million rows.

### Notes

Filter out `pitches_continue_next_row` before summing pitches, or filter to
`is_plate_appearance`. Either gives the correct total. This is the single
easiest mistake to make with this data.

Request one season at a time until the shape of the query is settled.

`game_id` matches the identifier used across all Retrosheet products, so this
joins directly onto game-level data.

### Support

Open the **Issues** tab with the `game_id` and the play in question.

### Licence and attribution

The information used here was obtained free of charge from and is copyrighted by
Retrosheet. Interested parties may contact Retrosheet at "www.retrosheet.org".

Retrosheet permits commercial use explicitly, on the single condition that the
notice above appears prominently. Every row carries the licence, and every run
records it in the run summary.

# Actor input Schema

## `fromSeason` (type: `integer`):

First season. Retrosheet has play-by-play back to 1915, though the earliest years are partial.

## `toSeason` (type: `integer`):

Last season. Leave it equal to the first for a single year — each season is roughly 250,000 plays.

## `teams` (type: `array`):

Retrosheet team codes. A play is returned if either side matches. Empty means every team.

## `maxPlays` (type: `integer`):

Stop after this many. **0 removes the cap.** A full season is around 250,000 plays, so keep the cap on unless you mean it.

## Actor input object example

```json
{
  "fromSeason": 2024,
  "toSeason": 2024,
  "teams": [],
  "maxPlays": 1000
}
```

# Actor output Schema

## `plays` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("sourcerow/mlb-play-by-play").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("sourcerow/mlb-play-by-play").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call sourcerow/mlb-play-by-play --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,sourcerow/mlb-play-by-play"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/nP5yp4JskFs3NbNQb/builds/1Qw2xGa2VOJn72HR0/openapi.json
