Skip to main content

retrosheetpy

Fast, strongly-typed Retrosheet baseball data downloader, parser, and database ingestor.

PyPI version Python Versions CI Status License Documentation


retrosheetpy brings modern, typed data workflows to Retrosheet baseball archives. It enables baseball researchers, analysts, professors, and DBAs to download, parse, and ingest play-by-play events, historical game logs, rosters, schedules, and biographical encyclopedias directly into DuckDB, Parquet, Polars, pandas, and cloud SQL warehouses with strongly-typed schemas (integers, dates, booleans—never raw text dumps).

Powered by chadwickpy for multi-core play-by-play parsing with zero C compiler dependencies.


Key Features

  • Zero C Compiler Required: 100% pure Python / PyArrow / DuckDB, installable on Windows, macOS, and Linux in seconds.
  • Strongly Typed Schemas: Dates are parsed to DATE, counts and scores to INTEGER, flags to BOOLEAN—ready for instant SQL queries without manual casting.
  • Complete Retrosheet Catalog:
    • Events (Play-by-play, 164 columns via chadwickpy)
    • Postseason & All-Star Games (World Series, LCS, LDS, All-Star play-by-play)
    • Game Logs (1871–present, 161 columns)
    • Official Schedules (1877–present, 13 columns)
    • Biographical Encyclopedia (biofile0.csv, 32 columns)
    • Team Rosters (.ROS player records, handedness, teams)
    • Ballparks (parkcode.txt, history, dates, coordinates)
    • Transactions & Ejections (tran.txt, ejections.csv)
  • Compact CLI: Compact flags (-s, -y, -d, -c, -f, -o) for downloading, ingesting, exporting, and generating DDL.
  • Cloud Warehouses via dlt: Stream directly into PostgreSQL, Snowflake, BigQuery, ClickHouse, or Databricks via optional dlt.
  • LLM Context Ready: Includes llms.txt and llms-full.txt conforming to the llmstxt.org specification for AI agents.

Installation

# Core library (DuckDB, PyArrow, Polars, pandas, Parquet)
pip install retrosheetpy

# With cloud warehouse connectors (PostgreSQL, Snowflake, BigQuery)
pip install "retrosheetpy[dlt]"

Quickstart

Python API

import retrosheetpy as rs

# 1. Download & inspect 2024 MLB play-by-play events
events = rs.events(year=2024, backend="polars")
print(events.select(["GAME_ID", "BAT_ID", "PIT_ID", "EVENT_TX"]))

# 2. Historical Game Logs (1871-present)
gamelogs = rs.game_logs(year=range(2020, 2025), backend="polars")

# 3. Ballpark Directory & Rosters
parks = rs.parks(backend="arrow")
rosters_2024 = rs.rosters(year=2024, backend="polars")

# 4. Schedules, Biofile, Ejections, Transactions
schedules = rs.schedules(year=2024, backend="polars")
bio = rs.bio(backend="polars")
ejections = rs.ejections(backend="polars")
transactions = rs.transactions(backend="polars")

# 5. Ingest decades directly into DuckDB
rs.to_duckdb(
    path="retrosheet.duckdb",
    years=range(2000, 2025),
    datasets=["events", "gamelogs", "rosters", "parks", "schedules", "bio"],
)

# 6. Stream into PostgreSQL via dlt
rs.to_dlt(
    destination="postgres",
    years=[2024],
    datasets=["events", "gamelogs", "rosters", "parks"],
    credentials="postgresql://user:pass@localhost:5432/retrosheet",
)

Command-Line Interface (CLI)

# Download and cache all 2024 assets locally
retrosheetpy download -s all -y 2024

# Ingest into local DuckDB
retrosheetpy ingest -d duckdb -c retro.duckdb -s events,gamelogs -y 2020-2024

# Ingest into PostgreSQL warehouse
retrosheetpy ingest -d postgres -c "postgresql://user:pass@localhost:5432/retrosheet" -s all -y 2024

# Export specific dataset to Parquet
retrosheetpy export -s gamelogs -y 2024 -f parquet -o gamelogs_2024.parquet

# Generate production SQL DDL
retrosheetpy ddl -s events --dialect postgres
retrosheetpy ddl -s schedules --dialect bigquery

Documentation & LLM Resources


License & Attribution

retrosheetpy is licensed under GPL-3.0-or-later.

The information used in this project is obtained free of charge from and is copyrighted by Retrosheet. Interested parties may contact Retrosheet at www.retrosheet.org.

Metadata

Release files for retrosheetpy 2.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 retrosheetpy 2.1.0
File Size Uploaded
retrosheetpy-2.1.0.tar.gz 71.8 kB Details

Built distribution (wheel)

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

Total release size: 128.3 kB

Release files / retrosheetpy-2.1.0.tar.gz

Download URL retrosheetpy-2.1.0.tar.gz
Size 71.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a9aa4a96281c0750e8cfa8b64e716ed64a02d297ff8b9979cf07d89e360f3a1a
BLAKE2b-256 checksum
How to use checksums
919dd1ec43bd9e17d7865fbc2efe4cd0f4e984031dc711a7286419a4559a7567
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 Oct 13, 2026.

Transparency log

Release files / retrosheetpy-2.1.0-py3-none-any.whl

Download URL retrosheetpy-2.1.0-py3-none-any.whl
Size 56.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af3efea0095aed16e1361fd7406c5312f40fa37ffbeffb053512e6dfc3bc346c
BLAKE2b-256 checksum
How to use checksums
8b2d7fb85428c14e3e85485c6652e5d509fc7bae26e1a9c3bf9ac583053dd2ea
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 Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

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