Pydantic v2 typed client for the MLB Stats API
Project description
mlb-statsapi-pydantic
Pydantic v2 typed client for the MLB Stats API.
Note: This project is in early pre-release. The API surface may change between versions.
Every response is parsed into fully-typed Pydantic models with extra="allow" for forward compatibility. Includes both sync and async clients.
Install
pip install mlb-statsapi-pydantic
Quick start
from mlb_statsapi import MlbClient
with MlbClient() as client:
# Today's schedule
schedule = client.schedule(date="07/01/2024")
for date in schedule.dates:
for game in date.games:
print(f"{game.teams.away.team.name} @ {game.teams.home.team.name}")
# Team info
teams = client.teams(sport_id=1)
for team in teams.teams:
print(f"{team.name} ({team.abbreviation})")
# Standings
standings = client.standings(season=2024)
for record in standings.records:
for entry in record.team_records:
print(f"{entry.team.name}: {entry.wins}-{entry.losses}")
# Live game data
game = client.game(game_pk=745570)
print(game.game_data.teams.home.name)
Async
import asyncio
from mlb_statsapi import AsyncMlbClient
async def main():
async with AsyncMlbClient() as client:
schedule = await client.schedule(date="07/01/2024")
print(schedule.dates[0].games[0].teams.home.team.name)
asyncio.run(main())
See examples/ for more details
Features
- Fully-typed Pydantic v2 models for all major endpoints
- Sync (
MlbClient) and async (AsyncMlbClient) HTTP clients - Enum helpers for game types and team IDs
- Endpoint registry with URL building and parameter validation
extra="allow"on all models — new API fields won't break your code- PEP 561 compatible (
py.typed)
Development
git clone https://github.com/DarkSideOfTheMat/mlb-statsapi-pydantic.git
cd mlb-statsapi-pydantic
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install
Run checks
ruff check src/ tests/ # lint
ruff format --check src/ # format check
mypy # type check
pytest -q # tests
pytest --cov -q # tests with coverage
Copyright Notice
This package and its author are not affiliated with MLB or any MLB team. This API wrapper interfaces with MLB's Stats API. Use of MLB data is subject to the notice posted at http://gdx.mlb.com/components/copyright.txt.
This project is inspired by MLB-StatsAPI by Todd Roberts, licensed under GPL-3.0.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlb_statsapi_pydantic-0.0.1.tar.gz.
File metadata
- Download URL: mlb_statsapi_pydantic-0.0.1.tar.gz
- Upload date:
- Size: 483.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
018af901819266b70344b528731e83864041561dad80d8a24f159caa6f0c554d
|
|
| MD5 |
491d517c2a0a4664733ea6e2e9ed2821
|
|
| BLAKE2b-256 |
5dcc17f4b4da120006dc6aacebfa7b10a73d756c9b4d81be9b8f2bf4fb8ea787
|
Provenance
The following attestation bundles were made for mlb_statsapi_pydantic-0.0.1.tar.gz:
Publisher:
publish.yml on DarkSideOfTheMat/mlb-statsapi-pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlb_statsapi_pydantic-0.0.1.tar.gz -
Subject digest:
018af901819266b70344b528731e83864041561dad80d8a24f159caa6f0c554d - Sigstore transparency entry: 1203834155
- Sigstore integration time:
-
Permalink:
DarkSideOfTheMat/mlb-statsapi-pydantic@c96c4471eec6cb14139b4928f0d4715aa0acf184 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/DarkSideOfTheMat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c96c4471eec6cb14139b4928f0d4715aa0acf184 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mlb_statsapi_pydantic-0.0.1-py3-none-any.whl.
File metadata
- Download URL: mlb_statsapi_pydantic-0.0.1-py3-none-any.whl
- Upload date:
- Size: 44.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02b15811ccd285c0ab2b11b82672a365b99af898d46f53bfb0c255089023e129
|
|
| MD5 |
1235fe5e5d599a0def069b5247857a43
|
|
| BLAKE2b-256 |
42cfdf861ffc253000cea48fe32d13ca7379943f40b5a8809e1860094fee22be
|
Provenance
The following attestation bundles were made for mlb_statsapi_pydantic-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on DarkSideOfTheMat/mlb-statsapi-pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlb_statsapi_pydantic-0.0.1-py3-none-any.whl -
Subject digest:
02b15811ccd285c0ab2b11b82672a365b99af898d46f53bfb0c255089023e129 - Sigstore transparency entry: 1203834161
- Sigstore integration time:
-
Permalink:
DarkSideOfTheMat/mlb-statsapi-pydantic@c96c4471eec6cb14139b4928f0d4715aa0acf184 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/DarkSideOfTheMat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c96c4471eec6cb14139b4928f0d4715aa0acf184 -
Trigger Event:
release
-
Statement type: