Guide

MLB pitch mix analysis in Python with FastballAPI

Short answer: call get_pitch_mix for a pitcher's season arsenal, then get_pitches for every pitch, and compute what the summary hides: usage by count, velocity as a start wears on, and a whiff rate you can audit. Paul Skenes threw 2,891 pitches in 2026, 40.8 percent four-seam fastballs at 96.4 mph, and his changeup drew the highest whiff rate at 0.372.

This is a descriptive exercise about how a pitcher uses his pitches. It does not evaluate any wager and none of the figures here are recommendations.

Two endpoints, two jobs

get_pitch_mix costs 5 credits and returns one row per pitch type for a pitcher's season: pitches thrown, usage share, average and maximum velocity, whiff rate, ball rate and balls in play. It is the fast answer to "what does he throw." It is also a summary, so it cannot tell you when he throws what.

get_pitches costs 10 credits a page and returns the individual pitches: pitch_type, velocity, balls, strikes, inning, half, batter_id, a pixel location px and py, and a result such as strike-swinging, foul-ball, ball or ground-out. The default page is 500 rows. Within each game our check found at_bat_id values in nondecreasing order, so a running count within a game is the pitch count. Type and velocity are present on at least 96 percent of each season's pitches and on 99.8 percent or more from 2020, according to the response note. Automatic balls and strikes, such as intentional walks, are not pitches.

Look up the pitcher id with search_players, which costs 1 credit and takes a partial name. For Skenes it returned id 4719507, Pittsburgh, position SP.

Step 1: the arsenal

The script below pulls the arsenal and then all 2,891 pitches in six pages, 60 credits. It also loops until next_offset is null so a different pitcher with more or fewer pitches works unchanged. Set FASTBALLAPI_API_KEY before running it.

import json, os, time, urllib.error, urllib.request
import numpy as np, pandas as pd

KEY = os.environ["FASTBALLAPI_API_KEY"]
def post(tool, body):
    req = urllib.request.Request(f"https://mcp.fastballapi.com/v1/{tool}", data=json.dumps(body).encode(),
          headers={"Content-Type": "application/json", "x-api-key": KEY})
    for wait in (2, 5, 10, 20):
        try:
            with urllib.request.urlopen(req, timeout=90) as r:
                return json.load(r)["data"]
        except urllib.error.HTTPError as e:
            if e.code != 429:
                raise
            time.sleep(wait)

pid = post("search_players", {"name": "skenes", "limit": 1})["players"][0]["player_id"]
mix = pd.DataFrame(post("get_pitch_mix", {"pitcher_id": pid, "season": 2026})["mix"])
print(mix[["pitch_type", "name", "pitches", "usage", "avg_velocity", "max_velocity", "whiff_rate", "ball_rate"]])

rows, offset = [], 0
while offset is not None:
    page = post("get_pitches", {"pitcher_id": pid, "season": 2026, "limit": 500, "offset": offset})
    rows += page["pitches"]
    offset = page.get("next_offset")
    if offset is not None and len(page["pitches"]) < 500:
        offset = None
df = pd.DataFrame(rows)
df.to_csv("skenes_pitches.csv", index=False)
mix.to_csv("skenes_mix.csv", index=False)
print(len(df), "pitches", df.game_id.nunique(), "games")

The second script reads the saved files and does the analysis: an audit of the whiff rate, usage by count, velocity by pitch number and average location.

import numpy as np, pandas as pd

df = pd.read_csv("skenes_pitches.csv")
mix = pd.read_csv("skenes_mix.csv")

# 1. Does our own count match the arsenal endpoint?
own = df.pitch_type.value_counts()
print((own / len(df)).round(3).head(4).to_dict())
swing = df.result.eq("strike-swinging") | df.result.str.contains("foul") | df.in_play
whiff = df.result.eq("strike-swinging").groupby(df.pitch_type).sum() / swing.groupby(df.pitch_type).sum()
per_pitch = df.result.eq("strike-swinging").groupby(df.pitch_type).mean()
audit = pd.concat([whiff.round(3).rename("swings denominator"), per_pitch.round(3).rename("pitches denominator"),
                   mix.set_index("pitch_type").whiff_rate.rename("endpoint")], axis=1)
print(audit)
print("max gap vs endpoint:", (audit.iloc[:, 0] - audit.endpoint).abs().max().round(4))

# 2. Usage by count state.
def state(r):
    if r.strikes == 2: return "two strikes"
    if r.balls > r.strikes: return "behind"
    if r.balls == 0 and r.strikes == 0: return "first pitch"
    return "ahead or even"
df["state"] = df.apply(state, axis=1)
usage = pd.crosstab(df.state, df.pitch_type, normalize="index").round(3)
print(usage[["FF", "SI", "ST", "SL", "CH", "FS"]])
print(df.state.value_counts().to_dict())

# 3. Velocity fade within starts, fastballs only.
ff = df[df.pitch_type == "FF"].copy()
ff["pitch_in_game"] = df.groupby("game_id").cumcount().reindex(ff.index) + 1
ff["bucket"] = pd.cut(ff.pitch_in_game, [0, 25, 50, 75, 100, 130])
print(ff.groupby("bucket", observed=True).velocity.agg(["mean", "size"]).round(2))
# 4. Average location per type (pixel frame, relative only).
print(df.groupby("pitch_type")[["px", "py"]].mean().round(0).loc[["FF", "SI", "ST", "SL", "CH", "FS"]])

Reading the arsenal table

The pull covered 32 games in 2026. His mix in order of usage:

PitchPitchesUsageAvg mphMax mphWhiff rateBall rate
Four-seam1,1790.40896.4990.2980.313
Sweeper4600.15983.9890.2930.367
Changeup3620.12588.2910.3720.475
Sinker3400.11896.2980.1510.321
Splitter2910.10192.8950.1780.357
Slider2480.08686.1900.3510.359
Curve110.00481.6850.3330.455

Three things stand out. The four-seam and sinker sit at almost the same speed, 96.4 and 96.2, but the four-seam draws a whiff rate of 0.298 and the sinker only 0.151. Same velocity, very different outcomes, which is what you would expect when one pitch is designed to miss bats and the other to induce contact. The changeup has both the highest whiff rate and the highest ball rate, 0.475, so it is a chase pitch that also gets thrown out of the zone often. And the curve is a rounding error at 11 pitches, so its 0.333 whiff rate rests on a handful of swings and should not be read as a number.

Audit the whiff rate

A summary you cannot reproduce is a summary you cannot trust, so recompute it. The endpoint's whiff rate matches swinging strikes divided by swings, where a swing is a swinging strike, any foul and any ball in play. Our recomputation reproduced every pitch type to within 0.004. For the splitter it gave 0.177 against the endpoint's 0.178, for the sinker 0.149 against 0.151, and for the sweeper 0.289 against 0.293. The small gaps most likely come from how a few edge-case result labels are classed, and we did not chase them down.

The tempting mistake is to divide swinging strikes by all pitches. That gives 0.165 for the four-seam against the endpoint's 0.298, a much lower figure, and it makes a pitch look worse simply because batters took more of them. Swings are the right denominator for a whiff rate. Know which one a number uses before comparing two sources.

Usage by count

The arsenal averages hide the sequencing. Classify every pitch by the count when it was thrown: first pitch (0-0), two strikes, behind (more balls than strikes without two strikes) and everything else. Then take row-normalised usage.

Count statePitchesFour-seamSinkerSweeperSliderChangeupSplitter
First pitch7130.3690.1540.2090.0460.0830.135
Ahead or even6440.4270.1100.1650.0820.1120.101
Behind6030.4460.1280.1210.0810.0710.151
Two strikes9310.4000.0880.1420.1210.2020.042

The pattern is readable. With two strikes the changeup usage jumps to 0.202 from between 0.071 and 0.112 in the other states, and slider usage rises to 0.121, which are the two pitches with whiff rates of 0.372 and 0.351. The sinker almost disappears at 0.088. On the first pitch he leans on the sweeper (0.209) and the sinker (0.154) and holds back the changeup and slider. When behind, he goes to the four-seam (0.446) and the splitter (0.151) and drops the sweeper to 0.121. The count states are mutually exclusive and add to 2,891.

Each cell rests on hundreds of pitches, not thousands, so a difference of 0.02 between two cells is within noise. The large moves, such as the changeup more than doubling with two strikes, are not.

Velocity as a start wears on

Take only four-seam fastballs, number each pitch within its game, and group the count into buckets.

Pitch of the gameMean four-seam mphPitches
1 to 2596.47359
26 to 5096.47320
51 to 7596.23303
76 to 10096.17187
101 to 13096.8010

Velocity is nearly flat. It drops about 0.3 mph between the first 50 pitches and the 76 to 100 bucket, and the last bucket has only 10 pitches, which is too few to read. A pitcher who holds his velocity this well gives you no fatigue signal in this view. For a pitcher who fades, the same code shows it clearly, and it is the first place to look when a manager's pitching change looks early.

Location with a pixel frame

px and py are a pixel frame, not feet. The average by type puts the four-seam at (122, 155) and the changeup at (136, 194), so the changeup sits at higher px and py values than the fastball on average. The sweeper (107, 176) and slider (103, 192) sit at lower px. Use the numbers to compare pitch types with each other. Do not use them to decide what is inside a rulebook zone, because the frame is not calibrated to one in the documentation.

Extending it

Filter get_pitches by pitch_type to study one pitch across a season, for example how the changeup's velocity changed from April to September. Add batter_id to see how a pitcher approaches a given hitter. And pass season_type to get_pitch_mix to separate the postseason from the regular season. Since the pitch rows carry game_id, a season split by month is a groupby away.

Limits

  • One pitcher, one season. All figures are for Skenes in 2026. Other pitchers differ, and a reliever's 300 pitches would make every cell thin.
  • No batter handedness. get_pitches gives a batter_id but not a side, so left versus right splits need a lookup from the player endpoint.
  • Pixel locations. px and py rank pitches against each other but are not feet from the plate.
  • Small cells. The curve has 11 pitches and the last velocity bucket has 10. Do not read rates off cells like those.
  • Count states are coarse. Four buckets hide differences between 1-0 and 3-1, for example. Count-level tables need several seasons of data.

Live from the API

Free to embed on your own site, with no key needed. Get the embed code.

Get a free key Or download whole seasons as Parquet

Checked against the live API on 2026-12-06. Questions: hello@sportsdatahq.com.