Skip to main content

bigleague: baseball data and plots. An anime girl in a baseball jersey points at a glowing strike-zone heatmap.

bigleague

PyPI Python License: MIT

Fetch Statcast pitches, Baseball Savant leaderboards, FanGraphs stats, and MLB schedules and rosters from Python. Requests use asyncio, tabular results use Polars, and plots are returned as PNG bytes.

Quick start

Install with pip install bigleague or uv add bigleague. Requires Python 3.12+.

This saves a strike-zone plot of the pitches Shohei Ohtani saw in April 2025.

import asyncio
from datetime import date
from pathlib import Path

import bigleague as bl


async def main() -> None:
    ohtani = 660271  # MLBAM ID
    pitches = await bl.statcast_batter(ohtani, date(2025, 4, 1), date(2025, 4, 30))
    png = bl.strike_zone(pitches, "Shohei Ohtani, April 2025")
    Path("ohtani-april.png").write_bytes(png)


asyncio.run(main())
strike_zone hot_zones
Strike zone plot of Ohtani's April 2025 pitches, colored by pitch type Hot zone heatmap of Ohtani's 2025 batting average by zone
spray_chart stadium_outline
Spray chart of Ohtani's 2025 batted balls at Dodger Stadium Dodger Stadium outline

The strike-zone plot covers April 2025. The hot zones and spray chart use Ohtani's season data. Passing stadium_key="dodgers" to spray_chart selects batted balls at Dodger Stadium.

Fetching data

Statcast

ohtani = await bl.resolve_id("Shohei", "Ohtani")  # 660271
if ohtani is not None:
    pitches = await bl.statcast_season(ohtani, 2025, "batter")
    print(bl.hot_cold_batter(pitches))

yankees = await bl.statcast(date(2025, 4, 1), date(2025, 4, 7), team="NYY")

resolve_id looks up an MLBAM ID in the Chadwick Bureau register. Use lookup("Ohtani", "Shohei") for the register rows.

statcast_batter and statcast_pitcher take a date range. statcast takes an optional team and splits the range into requests of up to seven days. bigleague allows up to five concurrent Savant requests. See STATCAST_SCHEMA for the pitch columns and their Polars types.

Savant leaderboards include sprint speed, expected stats, pitch arsenals, and pitch movement. Automated Ball-Strike challenge data is available under bl.abs.

speed = await bl.sprint_speed(2025)
challenges = await bl.abs.team_summary("NYY", 2025)

FanGraphs

ohtani = await bl.player_stats("Shohei", "Ohtani", 2025)
war_leaders = await bl.top_leaderboard("WAR", 2025, n=10)
batting = await bl.batting_stats(2024, 2025, qual=100)

batting_stats, pitching_stats, and fielding_stats return Polars DataFrames. If Cloudflare blocks a request, bigleague raises FangraphsBlockedError.

MLB Stats API

season = await bl.schedule("NYY", 2025)
last_five = [game for game in season if game["status"] in {"W", "L"}][-5:]
for game in last_five:
    print(game["date"], game["opponent"], game["score"], game["record"])

schedule defaults to the regular season. It returns games in play order with the team's running win-loss record. Status is W or L for final games, P for postponed or suspended games, and S for scheduled games.

Use team abbreviations such as NYY or LAD with live_scores, next_game, recent_results, roster, injuries, and transactions. Use standings(year) for division standings. Player lists are available through bl.mlb.players and bl.mlb.players_multi_season.

Cache

Historical Statcast data is cached as Parquet under ~/.bigleague/cache. Chunks ending today or later are fetched each time. The Chadwick player register uses the same directory.

Set BIGLEAGUE_CACHE_DIR to move the cache or BIGLEAGUE_NO_CACHE=1 to skip cache reads and writes for a run. Statcast entries stay on disk until you remove them. Use bl.cache.size() to check their size and bl.cache.clear() to remove them.

The optional bigleague[bloom] extra skips disk lookups for keys the cache doesn't contain.

Benchmarks

These runs use Ohtani's 2025 Statcast data. The month is April, and the season run covers April through September. Each library ran in its own process. For the warm run, bigleague read from its Parquet cache while the other two fetched the data again. The hotzones run calculates batting average by zone.

lib scenario rows frame peak heap peak RSS wall
bigleague month cold 426 194 KB 52 MB 161 MB 1.35s
pybaseball month cold 426 433 KB 85 MB 260 MB 2.69s
pandas+pyarrow month cold 426 375 KB 48 MB 167 MB 1.27s
bigleague month warm 426 193 KB 48 MB 151 MB 1.20s
pybaseball month warm 426 433 KB 85 MB 260 MB 2.60s
pandas+pyarrow month warm 426 375 KB 48 MB 166 MB 1.27s
bigleague season 2859 1.3 MB 55 MB 168 MB 1.40s
pybaseball season 2850 2.8 MB 96 MB 281 MB 2.71s
pandas+pyarrow season 2859 2.5 MB 51 MB 176 MB 1.29s
bigleague hotzones 426 193 KB 48 MB 158 MB 1.23s
pybaseball hotzones 426 433 KB 99 MB 290 MB 2.93s
pandas+pyarrow hotzones 426 375 KB 80 MB 250 MB 2.21s

The benchmark requires network access.

uv pip install pybaseball pandas pyarrow
uv run python bench/compare_pybaseball.py

Development

git clone https://github.com/klobucar/bigleague
cd bigleague
uv sync --extra dev
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run ty check

The tests mock HTTP requests. Add --extra bloom to uv sync to run the Bloom filter tests.

Regenerate the gallery from the repository root with uv run python -m docs.make_gallery. It fetches data from Baseball Savant and writes the PNGs to docs/img/.

Used by

harry-bot, a Discord baseball bot.

License

MIT. bigleague is an independent project. Check the data providers' terms before commercial use.

Metadata

Release files for bigleague 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bigleague 0.1.0
File Size Uploaded Provenance Actions
bigleague-0.1.0.tar.gz 65.7 kB With provenance Details for bigleague-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bigleague 0.1.0
File Interpreter ABI Platform Actions
bigleague-0.1.0-py3-none-any.whl Python 3 none any Details for bigleague-0.1.0-py3-none-any.whl

Total release size: 112.1 kB

Release files / bigleague-0.1.0.tar.gz

Download URL bigleague-0.1.0.tar.gz
Size 65.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0bfa60af69c6579529d107cb6ce4396d3b69c790caa38e7ea6554e91fbe27c92
BLAKE2b-256 checksum
How to use checksums
f25419b486aa7d503d968874cbd6bb550298ac741e5263644b7d39e3c7dad759
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / bigleague-0.1.0-py3-none-any.whl

Download URL bigleague-0.1.0-py3-none-any.whl
Size 46.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f9a2e10e2d7c14c1c7563de9d8a808214c0295ff28979419f0b016035f49420
BLAKE2b-256 checksum
How to use checksums
55e70050fd7b87ea11167f1ae60c5823c9a7dc04a4f2845540d75f27c38e1b03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for bigleague 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bigleague-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page