Skip to main content

pybaseballstats

A Python package for scraping baseball statistics from the web. Inspired by the pybaseball package by James LeDoux.


PyPI Downloads Pytest Status Type Check Status


Available Sources

  1. 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.
  2. Umpire Scorecards
    • This source has umpire game logs that start in 2008. This package accepts date ranges from 2015 onward.
  3. Baseball Reference
    • This source provides comprehensive, high detail stats for all MLB players and teams since 1871.
  4. 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.

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. For changes to enum imports, empty results, and errors, see the public API migration guide.

General Documentation (Things of Note)

Use from pybaseballstats import statcast as sc for a source module and from pybaseballstats.enums import StatcastTeams for its team filter. The same source modules also support qualified imports and direct function imports. Modules with an initial underscore are private implementation details.

Most functions return a Polars DataFrame. Statcast pitch-by-pitch functions return a LazyFrame by default; call .collect() to get a DataFrame, or pass force_collect=True. A valid response with no matching rows returns an empty result of the documented type. Wrong argument types raise TypeError; invalid values raise ValueError; request and source-data failures inside a call raise RuntimeError. A lazy query can raise a Polars error later at .collect().

Baseball Reference functions use a shared session and a process-local request limiter. The source can still block requests. A failed request raises an error. The package does not verify that every upstream page is available now.

To convert an eager Polars DataFrame to pandas, call .to_pandas():

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.5

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

Source distribution (sdist)

Source distribution for pybaseballstats 0.6.5
File Size Uploaded Provenance Actions
pybaseballstats-0.6.5.tar.gz 62.9 kB With provenance Details for pybaseballstats-0.6.5.tar.gz

Built distribution (wheel)

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

Total release size: 146.4 kB

Release files / pybaseballstats-0.6.5.tar.gz

Download URL pybaseballstats-0.6.5.tar.gz
Size 62.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5b40f10392cfa96828f29e8071936f0942631f77270f6e2c993ad3a2b41f0506
BLAKE2b-256 checksum
How to use checksums
6475a9543e768fe1eeca70e4ed403dd1c4aedcb5919b42639515bd79309a3415
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 13, 2026.

Transparency log

Release files / pybaseballstats-0.6.5-py3-none-any.whl

Download URL pybaseballstats-0.6.5-py3-none-any.whl
Size 83.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87f979592562e55b18e5c06d1e8183db1c099648ed6e304149c0a63e0b65d70e
BLAKE2b-256 checksum
How to use checksums
0b4cfe03e1bd3dbbf09fa7afe15e20967b20015051eeb4463035b95803806a00
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 13, 2026.

Transparency log

Security for pybaseballstats 0.6.5

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 pybaseballstats-0.6.5.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 13, 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.

Release history Release notifications | RSS feed

This release

0.6.5 This release

2 release files Full provenance

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