pybaseball
Retrieve baseball data in Python
What it is and what it does
Pybaseball is a Python library that automates retrieval of Major League Baseball data from three major public sources: Baseball Reference, Baseball Savant, and FanGraphs. Instead of manually navigating websites or parsing HTML, you call functions to fetch statcast pitch-level data, season-level batting and pitching statistics, team standings, game schedules, and awards data as pandas DataFrames. The library handles web scraping using beautifulsoup4, requests, and lxml under the hood.
The package is designed for baseball analysts, researchers, and enthusiasts who want to work with MLB data programmatically. Data is available at multiple granularities: individual pitches (via statcast), per-player per-season aggregates (via pitching_stats and batting_stats), and custom time ranges. It integrates with pandas and numpy for downstream analysis, and supports matplotlib for visualization. The aging maintenance status means web scraping may occasionally break if target sites change their structure, but the core functionality remains useful for historical and recent data analysis.
Use it for:
- Retrieve pitch-level statcast data for a date range to analyze pitcher performance metrics like spin rate and release speed.
- Pull multi-season batting or pitching statistics from FanGraphs for cohort analysis or player comparison studies.
- Fetch a team's game-by-game schedule and results for a historical season to study win-loss patterns.
- Query player-specific statcast data using playerid_lookup to build custom performance dashboards.
- Combine standings data with schedule results to track division races and playoff implications over time.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Scrapes baseball data from Baseball Reference, Baseball Savant, and FanGraphs, returning statcast pitch-level data, batting and pitching statistics, standings, and schedule information as pandas DataFrames.
Yes, with conditions. Install if you need to work with MLB data and can tolerate occasional scraping breakage when target websites change. The low install friction, permissive MIT license, and stable dependency stack make it straightforward to add. However, the aging maintenance status (last release 2023-09-08) means you should verify that the specific data sources you need are still accessible before committing to it for production pipelines. No known security vulnerabilities.
Install
pybaseball on PyPI
pip
pip install pybaseballuv
uv add pybaseballpoetry
poetry add pybaseballInstalling pybaseball
Before you install
Low install friction with a pure-Python wheel. Maintenance status is aging—last release was 2023-09-08 and last commit 2026-01-04—but the repository remains active and unarchived with 1717 stars. The 11 runtime dependencies (numpy, pandas, beautifulsoup4, requests, lxml, pyarrow, pygithub, scipy, matplotlib, tqdm, attrs) are all stable, widely-used libraries.
License in practice
MIT license is permissive, allowing commercial and private use with minimal restrictions. No licensing barrier to adoption.
Quickstart
pip install pybaseball
from pybaseball import statcast, pitching_stats
data = statcast(start_dt="2019-06-24", end_dt="2019-06-25")
stats = pitching_stats(2014, 2016)
Verify before relying
- Whether scraped data remains current given that Baseball Reference, Savant, and FanGraphs may change their HTML/API structures without notice.
- Performance characteristics when querying large date ranges or multiple seasons.
- Whether the package handles rate-limiting or connection failures gracefully.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 11 — numpy, pandas, beautifulsoup4, requests, lxml, pyarrow, pygithub, scipy, matplotlib, tqdm, attrs |
| Maintenance | aging — 1,071 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 290,653/month — #7,985 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pybaseball-2.2.7-py3-none-any.whl
Keywords: baseball, sabermetrics, data, statistics, statcast, web, scraping
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
MLB-StatsAPIProvides Python access to MLB's Stats API,…
copyleft · top 15,000 on PyPI
nba_apinba_api provides Python access to NBA.com's…
permissive · top 15,000 on PyPI
nflreadpyDownloads and caches NFL data from nflverse…
permissive · top 15,000 on PyPI
statsbombpyStreams StatsBomb football analytics data into…
unclear · top 15,000 on PyPI
nfl-data-pyImports NFL play-by-play, weekly, seasonal,…
permissive · top 15,000 on PyPI
fredapifredapi wraps the FRED web service to fetch…
unclear · top 5,000 on PyPI
wbdataWbdata provides a Python interface to query and…
copyleft · top 5,000 on PyPI
runstatsComputes summary statistics (mean, variance,…
permissive · top 15,000 on PyPI
ucimlrepoImports datasets from the UC Irvine Machine…
permissive · top 15,000 on PyPI
pyreadstatReads and writes SAS, SPSS, and Stata data…
permissive · top 5,000 on PyPI