Metadata-Version: 2.5
Name: sportsdatahq
Version: 0.1.0
Summary: One Python client for nine sports data APIs: NBA, NFL, NHL, MLB, soccer, tennis, golf, MMA and cricket. Stats, schedules, odds and player props. No dependencies.
Project-URL: Homepage, https://sportsdatahq.com/?utm_source=pypi&utm_medium=sportsdatahq
Project-URL: Documentation, https://sportsdatahq.com/docs?utm_source=pypi&utm_medium=sportsdatahq
Project-URL: Repository, https://github.com/sports-data-hq/sdhq
Project-URL: Get a free key, https://app.sportsdatahq.com/signup?utm_source=pypi&utm_medium=sportsdatahq&utm_campaign=pypi_page
Author-email: SportsDataHQ <support@sportsdatahq.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api-client,cricket,golf,mlb,mma,nba,nfl,nhl,odds,pandas,player-props,soccer,sports-data,tennis
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
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

# SportsDataHQ for Python

One package for nine sports data APIs: NBA, NFL, NHL, MLB, soccer, tennis, golf, MMA and cricket. Schedules, scores, player stats, standings, ratings, sportsbook lines and player props, as plain dicts or pandas DataFrames.

No required dependencies (standard library only), Python 3.9 and newer. Every call goes to the live API with your own key; the package ships no data.

## 60-second quickstart

```bash
pip install "sportsdatahq[pandas]"
```

```python
import sportsdatahq as sdhq

sdhq.login()          # once: opens the free signup page, you paste the key, it is saved for next time

client = sdhq.Client()

# NFL passing-yard props for one game, by sportsbook, as a DataFrame (10 credits)
props = client.nfl.player_props("2025_01_KC_LAC", "player_pass_yds", bookmaker="draftkings")
print(props.df("props")[["player_name", "line", "over_odds", "under_odds"]])

# NBA scores for a date (2 credits)
for g in client.nba.games(date="2026-03-15", limit=3)["games"]:
    print(g["away"]["abbrev"], g["away"]["score"], "at", g["home"]["abbrev"], g["home"]["score"])

print("credits left:", client.last_credits_remaining)
```

**Get a free key:** https://app.sportsdatahq.com/signup?utm_source=pypi&utm_medium=sportsdatahq&utm_campaign=readme. A SportsDataHQ key works for every sport, with 1,000 free credits a month and no card.

## Keys

`login()` saves the key to `~/.config/sportsdatahq/config.json`, readable only by you (mode 600). You can also set it yourself:

```bash
export SDHQ_API_KEY=sk_sdhq_...
```

Already have a key from one of the sport APIs (DunkAPI, EndzoneAPI, PuckAPI and so on)? It keeps working for its own sport:

```python
client = sdhq.Client(keys={"nba": "sk_live_...", "nfl": "sk_live_..."})
```

or through its usual variable (`DUNKAPI_API_KEY`, `ENDZONEAPI_API_KEY`, ...). `sdhq.login("nba")` saves a brand key for one sport. For each sport, the first key found wins:

1. `Client(keys={"nba": ...})`
2. `Client(api_key=...)`
3. `SDHQ_API_KEY`
4. the sport's own variable, such as `DUNKAPI_API_KEY` (or `DUNKAPI_KEY`)
5. the saved config file

A sport's key is looked up the first time you use that sport, so a script that only touches the NBA never needs an NFL key. If a sport has no key, the error names the page where you get one.

| Sport | Attribute | API | Brand key variable |
| --- | --- | --- | --- |
| NBA, WNBA, college basketball | `client.nba` | DunkAPI | `DUNKAPI_API_KEY` |
| NFL | `client.nfl` | EndzoneAPI | `ENDZONEAPI_API_KEY` |
| NHL and other hockey leagues | `client.nhl` | PuckAPI | `PUCKAPI_API_KEY` |
| MLB, college baseball | `client.mlb` | FastballAPI | `FASTBALLAPI_API_KEY` |
| Soccer (17 leagues) | `client.soccer` | StrikerAPI | `STRIKERAPI_API_KEY` |
| Tennis (ATP, WTA) | `client.tennis` | AcesAPI | `ACESAPI_API_KEY` |
| Golf (PGA Tour, LPGA, LIV, DP World, Korn Ferry) | `client.golf` | BirdieAPI | `BIRDIEAPI_API_KEY` |
| MMA (UFC, PFL, Bellator) | `client.mma` | FighterAPI | `FIGHTERAPI_API_KEY` |
| Cricket | `client.cricket` | YorkerAPI | `YORKERAPI_API_KEY` |

## The core functions

The same names work on every sport. Each maps to one API tool; credits are per call.

| Function | NBA | NFL | NHL | MLB | Soccer | Tennis | Golf | MMA | Cricket | Credits |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `teams()` | list_teams | list_teams | list_teams | list_teams | list_teams | - | - | - | list_teams | 1 |
| `find_player(name)` | search_players | search_players | search_players | search_players | search_players | search_players | search_players | search_fighters | search_players | 1-2 |
| `schedule()` | get_schedule | get_schedule | get_schedule | get_schedule | get_schedule | get_schedule | get_schedule | get_schedule | get_schedule | 1-2 |
| `games(...)` | list_games | get_games | get_games | get_games | list_games | get_matches | list_tournaments | list_events | get_matches | 1-5 |
| `standings()` | get_standings | get_standings | get_standings | get_standings | get_standings | get_rankings | - | - | - | 2 |
| `player(id)` | get_player | get_player_stats | get_player_stats | get_player | get_player | get_player | get_player | get_fighter | get_player | 5 |
| `player_games(id)` | get_player_games | get_player_stats | get_player_game_log | get_player_games | get_player_games | get_player_matches | get_player_results | get_fighter_fights | get_player_matches | 5 |
| `leaders(stat)` | get_leaders | get_player_leaders | get_skater_season_stats | get_leaders | get_leaders | - | get_leaders | get_leaders | get_leaders | 5 |
| `odds(game_id)` | get_odds | get_odds | get_odds | get_odds | get_odds | get_odds | get_winner_odds | get_odds | get_odds | 5-10 |
| `player_props(game_id, market)` | get_player_props | get_player_props | get_player_props | get_player_props | get_player_props | - | - | - | - | 10 |
| `prop_history(player_id, market)` | get_prop_history | get_prop_history | get_prop_history | get_prop_history | get_prop_history | - | - | - | - | 10 |
| `ratings()` | get_ratings | - | - | get_ratings | get_ratings | get_ratings | get_ratings | get_ratings | get_ratings | 2 |

A `-` raises `NotSupportedError`. `client.nba.cost("odds")` gives a call's price from the spec. Filters are keyword arguments with the API's names (`season=`, `team=`, `league="wnba"`, `limit=`); a Python keyword takes a trailing underscore (`from_="2026-03-01"`).

Every API tool is also a method with its full signature and docstring, so nothing is hidden behind the helpers:

```python
client.nhl.get_shifts(game_id="2026020080", team="TOR")
client.nba.get_shot_chart(player_id="...", season=2026)
client.soccer.call("get_lineups", {"game_id": "..."})   # any tool by name, including ones newer than this package
help(client.nfl.get_plays)
```

## DataFrames

Results are plain `dict`s and `list`s. `.df()` turns the main list into a pandas DataFrame, with nested fields as dotted columns:

```python
games = client.mlb.games(date="2026-07-04")
df = games.df()               # the longest list of records in the response
df = games.df("games")        # or name it
df = sdhq.to_dataframe(games, key="games")
```

pandas is optional: `pip install "sportsdatahq[pandas]"`.

## Credits and errors

After each call, `client.last_credits_used` and `client.last_credits_remaining` hold the counters from the response headers. Several tools take `estimate_only=True` to price a call without running it.

| Exception | When |
| --- | --- |
| `MissingKeyError` | No key for that sport. The message has the signup link. |
| `AuthError` | 401: the key is wrong or revoked. |
| `InsufficientCredits` | 402: not enough credits. Has `.required`, `.available`, `.refill_on` and `.upgrade_url`. |
| `PaidPlanRequired` | 403: a paid-plan tool on a free account. |
| `NotFoundError` | 404: the id does not exist. |
| `RateLimitError` | 429 after retries. Has `.retry_after`. |
| `NotSupportedError` | The sport has no tool for that helper. |
| `APIError` | Any other error. Every exception above is one. |

```python
try:
    client.nba.player_props("401810726", "player_points")
except sdhq.InsufficientCredits as e:
    print(e.message, e.upgrade_url)
```

429 and 5xx responses and dropped connections are retried up to 3 times with backoff (`Client(max_retries=0)` turns that off).

## Data rights

Calls are live. You may store what you pull, build models and products on it, and show your users what you derive. You may not redistribute the data, or odds as a raw feed, as a dataset or API of its own. Full terms: https://app.sportsdatahq.com/terms. Sportsbook lines are information about the market, not betting advice.

## License

MIT
