understatapi.api module

understatAPI client

class understatapi.api.UnderstatClient[source]

Bases: object

API client for understat

The main interface for interacting with understatAPI. Exposes each of the entrypoints, maintains a consistent session and handles errors

Example

from understatapi import UnderstatClient

with UnderstatClient() as understat:
    league_player_data = understat.league(league="EPL").get_player_data(season="2019")
    player_shot_data = understat.player(player="2371").get_shot_data()
    team_match_data = understat.team(team="Manchester_United").get_match_data(season="2019")
    roster_data = understat.match(match="14711").get_roster_data()

Using the context manager gives some more verbose error handling

>>> team=""
>>> with UnderstatClient() as understat:
...     understat.team(team).get_bad_data() 
Traceback (most recent call last)
File "<stdin>", line 2, in <module>
File "understatapi/api.py", line 59, in __exit__
    raise AttributeError(
AttributeError: 'TeamEndpoint' object has no attribute 'get_bad_data'
Its public methods are ['get_context_data', 'get_match_data', 'get_player_data']
league(league)[source]

Endpoint for league data. Use this function to get data from a url of the form https://understat.com/league/<league>/<season>

Parameters

league (Union[List[str], str]) – Name of the league(s) to get data for, one of {EPL, La_Liga, Bundesliga, Serie_A, Ligue_1, RFPL}

Return type

LeagueEndpoint

Example

>>> leagues = ["EPL", "Bundesliga"]
>>> with UnderstatClient() as understat:
...     for league in understat.league(leagues):
...         print(league.league)
EPL
Bundesliga
player(player)[source]

Endpoint for player data. Use this function to get data from a url of the form https://understat.com/player/<player_id>/

Parameters

player (Union[List[str], str]) – Id of the player(s) to get data for

Return type

PlayerEndpoint

Example

>>> player_ids = ["000", "111"]
>>> with UnderstatClient() as understat:
...     for player in understat.player(player_ids):
...         print(player.player)
000
111
team(team)[source]

Endpoint for team data. Use this function to get data from a url of the form https://understat.com/team/<team>/<season>

Parameters

team (Union[List[str], str]) – Name of the team(s) to get data for

Return type

TeamEndpoint

Example

>>> team_names = ["Manchester_United", "Liverpool"]
>>> with UnderstatClient() as understat:
...     for team in understat.team(team_names):
...         print(team.team)
Manchester_United
Liverpool
match(match)[source]

Endpoint for match data. Use this function to get data from a url of the form https://understat.com/match/<match_id>

Parameters

match (Union[List[str], str]) – Id of match(es) to get data for

Return type

MatchEndpoint

Example

>>> match_ids = ["123", "456"]
>>> with UnderstatClient() as understat:
...     for match in understat.match(match_ids):
...         print(match.match)
123
456