Metadata-Version: 2.4
Name: stat-api-client
Version: 0.3.1
Summary: Official Python client for the stat-api sports data API
Author: stat-api
License: MIT
Project-URL: Homepage, https://stat-api.com
Project-URL: Documentation, https://stat-api.com/docs
Project-URL: Repository, https://github.com/stat-api/stat-api/tree/main/python
Keywords: sports,stats,api,nba,nfl,mlb,nhl,golf
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<!-- DO NOT EDIT — generated by generate-python-sdk-public.ts -->

# stat-api-client

Official Python client for the [stat-api](https://stat-api.com) sports data API —
a single, typed surface over NBA, NFL, MLB, NHL, and PGA data.

Zero runtime dependencies (stdlib only). Python 3.10+.

## Install

```bash
pip install stat-api-client
```

## Authenticate

The client reads your API key from the `STAT_API_KEY` environment
variable, or you can pass it directly:

```python
from statapi import StatApi

api = StatApi()                      # reads STAT_API_KEY
api = StatApi(api_key="sdb_...")     # or pass it in
```

Point at a different host with `base_url=` or `STAT_API_BASE_URL`
(default `https://api.stat-api.com`).

## List, get, and iterate

```python
# One page (returns a Page[Row]).
page = api.nba.players.list(limit=25)
for player in page.rows:
    print(player["full_name"])

# Fetch one row by id.
player = api.nba.players.get(201939)

# Auto-paginate the whole result set (walks next_from_id for you).
for player in api.nba.players.iter(team_id=1):
    print(player["full_name"])
```

Rows are `TypedDict`s — access fields by subscript (`player["team_id"]`).
High-precision columns (dates, timestamps, decimals) arrive as strings so no
precision is lost on the wire.

## Errors

Every non-2xx response raises a typed exception; the raw server envelope is on
`.body`.

```python
from statapi import (
    StatApi,
    AuthenticationError,
    NotFoundError,
    QuotaExceededError,
    ValidationError,
    StatApiError,
)

try:
    api.nba.players.get(-1)
except NotFoundError:
    ...
except QuotaExceededError as err:
    print("quota resets at", err.resets_at, "→", err.upgrade_url)
except StatApiError as err:
    print(err.status, err.body)
```

| Status | Exception |
|-------|-----------|
| 400 | `ValidationError` |
| 401 | `AuthenticationError` |
| 402 | `PlanRequiredError` |
| 404 | `NotFoundError` |
| 429 | `QuotaExceededError` |
| other | `StatApiError` |

## NFL sim (beta)

The Python client has the core calls of the NFL play-by-play simulator. Game 43418 (2026 Week 1 DEN @ KC) is free. Other games need a Pro or Elite plan, or the DFS add-on.

- `api.nfl.weeks(season=...)`
- `api.sim.nfl.run(game_id=..., n_draws=..., seed=..., include=..., home_spread=...)`

The tutorial has 5 recipes. Each one runs on the free game and prints real output. Start with [Run your first NFL game simulation](../cookbook/python/nfl_sim_summary.py), or read the whole tutorial at https://stat-api.com/docs/cookbook/sim/.

The API reference: https://stat-api.com/docs/api/sim/

## Quota

Every response carries your monthly record quota. It's on each `Page` and on
`QuotaExceededError`:

```python
page = api.nba.players.list(limit=1)
if page.quota:
    print(page.quota.remaining, "of", page.quota.limit, "records left")
```

## License

MIT. See [LICENSE](./LICENSE).
