Python API Reference
This page contains the complete reference for retrosheetpy's Python module. All primary functions are directly accessible from the root namespace:
retrosheetpy.api
High-level user-facing API for retrosheetpy.
allstar
allstar(
year: int | Sequence[int],
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads, parses, and returns All-Star Game play-by-play events.
Source code in src/retrosheetpy/api.py
bio
bio(
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads and returns the master player and personnel biographical database.
Source code in src/retrosheetpy/api.py
download
download(
years: int | Sequence[int] | None = None,
datasets: Sequence[str] | str = "all",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> dict[str, list[Path]]
Downloads specified Retrosheet archives to local cache without loading them into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years | int | Sequence[int] | None | Year or sequence of years to download. Defaults to [2024] if not provided. | None |
datasets | Sequence[str] | str | Dataset or comma-separated list of datasets to download ('events', 'postseason', 'allstar', 'gamelogs', 'rosters', 'parks', 'schedules', 'bio', 'ejections', 'transactions', or 'all'). | 'all' |
force | bool | If True, re-downloads even if already cached. | False |
downloader | Downloader | None | Optional custom Downloader instance. | None |
source | Literal['github', 'retrosheet', 'auto'] | None | Optional source override ('github', 'retrosheet', or 'auto'). | None |
Returns:
| Type | Description |
|---|---|
dict[str, list[Path]] | Dictionary mapping dataset name to list of extracted paths or file locations. |
Source code in src/retrosheetpy/api.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
ejections
ejections(
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads and returns the official ejections database.
Source code in src/retrosheetpy/api.py
events
events(
year: int | Sequence[int],
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads, parses, and returns play-by-play events as a strongly-typed DataFrame or Arrow Table.
Source code in src/retrosheetpy/api.py
game_logs
game_logs(
year: int | Sequence[int],
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads, parses, and returns official game logs as a strongly-typed DataFrame or Arrow Table.
Source code in src/retrosheetpy/api.py
get_ddl
Returns the SQL DDL CREATE TABLE statement for a given dataset and dialect.
parks
parks(
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads and returns the official Retrosheet ballpark directory.
Source code in src/retrosheetpy/api.py
postseason
postseason(
year: int | Sequence[int],
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads, parses, and returns postseason play-by-play events.
Source code in src/retrosheetpy/api.py
rosters
rosters(
year: int | Sequence[int],
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads, parses, and returns annual team roster files (.ROS).
Source code in src/retrosheetpy/api.py
schedules
schedules(
year: int | Sequence[int] = 2024,
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads, parses, and returns official regular season game schedules.
Source code in src/retrosheetpy/api.py
to_dlt
to_dlt(
destination: str | Any,
years: int | Sequence[int] = 2024,
datasets: Sequence[str] = (
"events",
"gamelogs",
"rosters",
"parks",
),
pipeline_name: str = "retrosheet",
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
**dlt_kwargs: Any,
) -> Any
Runs a full dlt pipeline ingesting Retrosheet datasets into Postgres, Snowflake, DuckDB, etc.
Source code in src/retrosheetpy/api.py
to_duckdb
to_duckdb(
path: Path | str,
years: int | Sequence[int] = 2024,
datasets: Sequence[str] = (
"events",
"gamelogs",
"rosters",
"parks",
),
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> None
Ingests selected Retrosheet datasets into a DuckDB database.
Source code in src/retrosheetpy/api.py
to_parquet
to_parquet(
path: Path | str,
dataset: str,
years: int | Sequence[int] = 2024,
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Path
Exports a specific Retrosheet dataset to a Parquet file.
Source code in src/retrosheetpy/api.py
transactions
transactions(
backend: str = "arrow",
force: bool = False,
downloader: Downloader | None = None,
source: Literal["github", "retrosheet", "auto"]
| None = None,
) -> Any
Downloads and returns the historical player transactions database.
Note: Upstream Retrosheet discontinued updating transactions on November 26, 2021, transitioning ongoing maintenance to Baseball-Reference.