DEV Community

noah
noah

Posted on Originally published at fastballapi.com

How do I get a pitcher's pitch mix and whiff rate in Python?

A pitcher's arsenal for a season: how often each pitch is thrown, how hard, and how often it draws a swing and a miss.

Code verified October 10, 2026. It takes one call to get_pitch_mix, 5 credits.

The call

pitcher_id comes from search_players.

import requests
import pandas as pd

API_KEY = "YOUR_API_KEY"

resp = requests.post(
    "https://mcp.fastballapi.com/v1/get_pitch_mix",
    headers={"x-api-key": API_KEY},
    json={
        "pitcher_id": "42409",
        "season": 2026,
    },
    timeout=60,
)
resp.raise_for_status()
data = resp.json()["data"]

mix = pd.DataFrame(data["mix"])
print(data["pitcher"]["name"], data["pitches"], "pitches")
print(mix[["name", "usage", "avg_velocity", "max_velocity", "whiff_rate"]])
Enter fullscreen mode Exit fullscreen mode

You need requests and pandas (pip install requests pandas) and a free API key from FastballAPI.

What comes back

The data object, trimmed to the first rows. Every value is real output from the run above.

{
  "pitcher": {
    "id": "42409",
    "name": "Tarik Skubal"
  },
  "season": 2026,
  "pitches": 2450,
  "mix": [
    {
      "pitch_type": "FF",
      "name": "Four-seam FB",
      "pitches": 930,
      "usage": 0.38,
      "avg_velocity": 96.4,
      "max_velocity": 101,
      "whiff_rate": 0.256,
      "ball_rate": 0.283,
      "in_play": 161
    },
    {
      "pitch_type": "CH",
      "name": "Changeup",
      "pitches": 627,
      "usage": 0.256,
      "avg_velocity": 87.3,
      "max_velocity": 92,
      "whiff_rate": 0.473,
      "ball_rate": 0.348,
      "in_play": 106
    },
    "...3 more"
  ],
  "count": 5
}
Enter fullscreen mode Exit fullscreen mode

What to do next

  • get_pitches (10 credits). The individual pitches behind each row, with location, for your own features.
  • get_leaders (5 credits). Rank every qualified pitcher on a stat before you pick one to look at.

Originally published at fastballapi.com.

Top comments (0)