Metadata-Version: 2.5
Name: dunkapi
Version: 0.1.0
Summary: Python client for the DunkAPI NBA data API. No dependencies.
Project-URL: Homepage, https://dunkapi.com
Project-URL: Documentation, https://dunkapi.com/docs
Project-URL: Repository, https://github.com/noahowsh/puckapi
Project-URL: Sign up, https://dunkapi.com/signup
Author-email: DunkAPI <support@dunkapi.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api-client,betting,dunkapi,nba,odds,player-props,sports-data
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Provides-Extra: pandas
Requires-Dist: pandas>=1.5; extra == 'pandas'
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# DunkAPI for Python

Python client for the [DunkAPI](https://dunkapi.com) NBA data API. It has no required dependencies (standard library only) and works on Python 3.9 and newer. Pandas is optional.

## Install

```bash
pip install dunkapi
pip install "dunkapi[pandas]"   # only if you want DataFrames
```

## Set your key

Get a free key at https://dunkapi.com/signup. Free accounts get 500 credits a month.

```bash
export DUNKAPI_API_KEY=your_key_here
```

```python
from dunkapi import Client

client = Client()                      # reads DUNKAPI_API_KEY
client = Client(api_key="your_key")    # or pass it in
```

## Examples

### 1. Player props for one game

`get_player_props` returns every player's line for one market, by sportsbook.

```python
from dunkapi import Client, to_dataframe

client = Client()

props = client.get_player_props(
    game_id="401810726",
    market="player_points",
    bookmaker="draftkings",
)
df = to_dataframe(props, key="props")
print(df[["player_name", "line", "over_odds", "under_odds"]].head(10))
```

### 2. One player's prop history

`get_prop_history` shows how a player's line for a market moved across games. Search for the player id first.

```python
from dunkapi import Client, to_dataframe

client = Client()

jokic = client.search_players("Jokic", limit=1)["players"][0]
history = client.get_prop_history(
    jokic["player_id"],
    "player_points",
    from_date="2026-03-01",
    to_date="2026-03-08",
    bookmaker="draftkings",
    limit=10,
)
print(to_dataframe(history).head())
```

### 3. Games on a date, and scoring leaders

`list_games` needs a filter such as `date`, `season` or `team`.

```python
from dunkapi import Client

client = Client()

games = client.list_games(date="2026-03-15", limit=3)["games"]
for g in games:
    print(g["away"]["abbrev"], g["away"]["score"], "at", g["home"]["abbrev"], g["home"]["score"])

leaders = client.get_leaders("pts", limit=5)
for row in leaders["leaders"]:
    print(row["name"], row["team"], row["value"])
```

## Credits

Every method returns the `data` object from the response. After each call, `client.last_credits_used` and `client.last_credits_remaining` hold the counters from the `X-Credits-Used` and `X-Credits-Remaining` headers. Methods that take `estimate_only=True` return the price of a call without running or charging it.

## Pandas

```python
from dunkapi import to_dataframe

df = to_dataframe(data)                # finds the main list in the response
df = to_dataframe(data, key="rows")    # or name the list yourself
```

Nested fields become dotted columns. Install pandas separately or with `pip install "dunkapi[pandas]"`.

## Errors

Every error is an `APIError` subclass, with the server's message and the HTTP status.

| Exception | Status | Meaning |
| --- | --- | --- |
| `AuthError` | 401 | Missing, invalid or revoked key |
| `InsufficientCreditsError` | 402 | Not enough credits for the call |
| `NotFoundError` | 404 | The id or name does not exist |
| `RateLimitError` | 429 | Too many requests; has `.retry_after` when the server sends it |
| `APIError` | 400, 5xx | Bad arguments or a server problem |
| `APIConnectionError` | none | No response (network or timeout) |

```python
from dunkapi import Client, APIError, InsufficientCreditsError, RateLimitError

client = Client()
try:
    data = client.list_teams()
except InsufficientCreditsError:
    print("Out of credits, top up at https://dunkapi.com")
except RateLimitError as exc:
    print("Slow down, retry after", exc.retry_after)
except APIError as exc:
    print(exc.status_code, exc.message)
```

The client retries 429 and 5xx responses and connection failures up to 3 times with backoff, and honors `Retry-After`. Set `Client(max_retries=0)` to turn that off.

If you see `CERTIFICATE_VERIFY_FAILED` on a python.org install for macOS, run the "Install Certificates.command" script that came with Python, or `pip install certifi` (the client uses it when present).

## Options

```python
Client(
    api_key=None,                          # defaults to $DUNKAPI_API_KEY
    base_url="https://mcp.dunkapi.com",           # point at another host
    timeout=60.0,                          # seconds per request
    max_retries=3,
)
```

`client.call("tool_name", {"arg": "value"})` calls any tool by name, which helps when the API adds a tool before this package does.

## Tools

Method names match the API tool names. Arguments are keyword arguments; required ones can also be passed positionally. Each method's docstring lists its arguments (`help(client.list_teams)`).

| Method | Credits | What it does |
| --- | --- | --- |
| `list_teams` | 1 | List teams |
| `list_games` | 2 | List games |
| `get_schedule` | 2 | Schedule |
| `get_game` | 5 | Game |
| `get_standings` | 2 | Standings |
| `get_injuries` | 2 | Injuries |
| `search_players` | 1 | Search players |
| `get_player` | 5 | Player |
| `get_player_games` | 5 | Player games |
| `get_leaders` | 5 | Leaders |
| `get_team_stats` | 5 | Team stats |
| `get_plays` | 10 | Plays |
| `get_shot_chart` | 10 | Shot chart |
| `get_odds` | 5 | Odds |
| `get_line_movement` | 10 | Line movement |
| `get_ratings` | 2 | Ratings |
| `get_player_props` | 10 | Player props |
| `get_prop_history` | 10 | Prop history |

Full API reference: https://dunkapi.com/docs

## License

MIT
