pybaseballstats
A Python package for scraping baseball statistics from the web. Inspired by the pybaseball package by James LeDoux.
Available Sources
- Baseball Savant
- This source provides high quality pitch-by-pitch data for all MLB games since 2015, grouped single-player season summaries, and interesting leaderboards for various categories.
- Umpire Scorecards
- This source provides umpire game logs and statistics for all MLB games since 2008.
- Baseball Reference
- This source provides comprehensive, high detail stats for all MLB players and teams since 1871.
- Retrosheet
- This source provides play-by-play data for all MLB games since 1871. This data is primarily used for the player_lookup function as well as ejection data. I am considering adding support for the play by play data as well.
Temporary Baseball Reference outage (hotfix): As of the latest hotfix release, Baseball Reference-backed modules are temporarily disabled due to upstream Cloudflare anti-crawling protections. This was done to avoid flaky behavior and hard-to-diagnose failures while a robust workaround is investigated. Other data sources (Baseball Savant, Umpire Scorecards, Retrosheet) remain available.
Installation
pybaseballstats can be installed using pip or any other package manager (I use uv).
Examples:
uv add pybaseballstats
or:
pip install pybaseballstats
Some functions use Playwright and require its Chromium browser. Install it
after installing pybaseballstats:
# uv
uv run playwright install chromium
# pip or another Python environment
python -m playwright install chromium
On Linux, use --with-deps if the required system dependencies are missing:
python -m playwright install --with-deps chromium
Documentation
Usage documentation can be found in this folder. This documentation is a work in progress and will be updated as I add more functionality to the package.
General Documentation (Things of Note)
- This project uses Polars internally. This means that all data returned from functions in this package will be in the form of a Polars DataFrame. If you want to convert the data to a Pandas DataFrame, you can do so by using the
.to_pandas()method on the Polars DataFrame. For example: - The BREF functions use a singleton pattern to guarantee that you won't exceed rate limits and face a longer timeout. So: don't be surprised if when you are making multiple calls to BREF functions that these calls may be a little slower than expected. This is to be expected as the singleton pattern is used to ensure that only one instance of the BREF scraper is created and used throughout the lifetime of your program. This is done to avoid exceeding rate limits and being blocked by BREF.
import pybaseballstats.umpire_scorecards as us
df_polars = us.game_data(start_date="2023-04-01", end_date="2023-04-30")
# Convert to Pandas DataFrame
df_pandas = df_polars.to_pandas()
Contributing
See the contributing guide for development setup, testing, branching, pull requests, and release instructions.
Credit and Acknowledgement
This project was directly inspired by the pybaseball package by James LeDoux. The goal of this project is to provide a similar set of functionality with continual updates and improvements, as the original pybaseball package has lagged behind with updates and some key functionality has been broken.
All of the data scraped by this package is publicly available and free to use. All credit for the data goes to the organizations from which it was scraped.
Metadata
Release files for pybaseballstats 0.6.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pybaseballstats-0.6.4.tar.gz | 75.5 kB | With provenance | Details for pybaseballstats-0.6.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybaseballstats-0.6.4-py3-none-any.whl | Python 3 | none | any | Details for pybaseballstats-0.6.4-py3-none-any.whl |
Total release size: 167.3 kB
Release files / pybaseballstats-0.6.4.tar.gz
| Download URL | pybaseballstats-0.6.4.tar.gz |
|---|---|
| Size | 75.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd944324ed4841691861c8dbce7ebec2accf2cdb6e7d4753e98184559d85b975
|
|
BLAKE2b-256 checksum How to use checksums |
dba4967d7fec434ff80e8dfbb686e1e6877c0b1a884635e7c9db4dfa7a6b202d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 21, 2026.
Transparency logRelease files / pybaseballstats-0.6.4-py3-none-any.whl
| Download URL | pybaseballstats-0.6.4-py3-none-any.whl |
|---|---|
| Size | 91.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6015dc724f78581c26d9b3e6946bdee0c60d59a2d46dd73a8373aba7afb0fe70
|
|
BLAKE2b-256 checksum How to use checksums |
f031da94f64258b88f142bc4e12fb6d11017fb35ca2584637dbb45a7f58828b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 21, 2026.
Transparency logSecurity for pybaseballstats 0.6.4
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.
Attestation for pybaseballstats-0.6.4.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 Sep 21, 2026.
Transparency logA 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.