opendota package

Submodules

opendota.cli module

Console Script for <OPENDOTA/> API

@author: Hrishikesh Terdalkar

opendota.cli.main()[source]

Console Script for <OPENDOTA/> API Powered by python-fire

opendota.opendota module

Python Wrapper for <OPENDOTA/> API

The OpenDota API provides Dota 2 related data including advanced match data extracted from match replays.

OpenDota API Documentation: https://docs.opendota.com/

About

The OpenDota class serves as a python interface for the original OpenDota API in the form of a thin wrapper. The class assumes some familiarity with the OpenDota API.

All method calls return serializable python objects, as return by the API, in most cases a dict or a list. Response data is stored as JSON in a local directory (Default: ~/dota2), to prevent the load on OpenDota API.

Features

  • Functions for the most frequently used API calls

  • Ability to authenticate using API key

  • In-built and cusomizable limit to protect against frequent API calls

  • Local file-based storage for frequent requests (persistent cache)

class opendota.opendota.OpenDota(data_dir: Optional[str] = None, api_key: Optional[str] = None, delay: int = 3, fantasy: Optional[dict] = None, api_url: str = 'https://api.opendota.com/api')[source]

Bases: object

<OPENDOTA/> API Interface

Instance of a connection to OpenDota API. All methods return serializable python objects, which are also stored as JSON in the data_dir for future calls. All methods take a boolean argument force which, if True, will fetch the data again even if it is available in the data directory.

Parameters:
  • data_dir (str, (optional)) – Path to data directory for storing responses to API calls The default is ~/dota2.

  • api_key (str, (optional)) – If you have an OpenDota API key The default is None.

  • delay (int, (optional)) – Delay in seconds between two consecutive API calls. It is recommended to keep this at least 3 seconds, to prevent hitting the daily API limit. If you have an API key, this value is ignored. The default is 3.

  • fantasy (dict, (optional)) –

    Fantasy DotA2 Configuration Utility constant FANTASY holds the standard values and is used as default. Keys of the fantasy will override the default values. They must be a subset of the keys of FANTASY.

    Parameters ending with _base are used as base values, while others are used as multipliers. e.g. deaths = -0.3 and deaths_base = 3 results in the calculation as, death_score = 3 + (number_of_deaths * -0.3) If _base parameter is absent, it’s assumed to be 0.

  • api_url (str, (optional)) – URL to OpenDota API. It is recommended to not change this value.

data_dir: str = None
api_key: str = None
delay: int = 3
fantasy: dict = None
api_url: str = 'https://api.opendota.com/api'
request(url: str, *, post: bool = False, data: Optional[dict] = None, filename: Optional[str] = None, force: bool = False) Any[source]

Make a GET or POST request to <OPENDOTA/> API

Parameters:
  • url (str) – API path to query

  • post (bool, (optional)) – Make a POST request. The default is False.

  • data (dict, (optional)) – Query Data. The default is None.

  • filename (str, (optional)) – Save the data to this file. The default is None.

  • force (bool, (optional)) – Force-fetch and overwrite data. The default is False.

Returns:

Result of the API call deserialized as a python object

Return type:

object

get(*args, **kwargs)[source]

Make a GET request to <OPENDOTA/> API.

Calls .request() with post=False

post(*args, **kwargs)[source]

Make a POST request to <OPENDOTA/> API

Calls .request() with post=True

request_parse(match_id: int)[source]

Submit a new parse request

request_status(job_id: int)[source]

Get parse request state

get_constant_names(force: bool = False)[source]

Get an array of available resources

get_constants(resource: Optional[str] = None, force: bool = False)[source]

Get static game data for specified resource(s) (mirrored from the dotaconstants repository)

Parameters:

resource (str or list,) – Name or names of resources

get_heroes(force: bool = False)[source]

Get hero data

get_hero_stats(force: bool = False)[source]

Get stats about hero performance in recent matches

get_hero_benchmarks(hero_id: int, force: bool = False)[source]

Get benchmarks for a hero

get_leagues(force: bool = False)[source]

Get a list of leagues

get_league(league_id: int, force: bool = False)[source]

Get data for a league

get_league_matches(league_id: int, force: bool = False)[source]

Get matches from a league

get_league_teams(league_id: int, force: bool = False)[source]

Get teams from a league

get_teams(force: bool = False)[source]

Get team data

get_team(team_id: int, force: bool = False)[source]

Get data for a team

get_team_matches(team_id: int, force: bool = False)[source]

Get matches for a team

get_team_players(team_id: int, current: bool = True, force: bool = False)[source]

Get players who have played for a team

get_team_heroes(team_id: int, force: bool = False)[source]

Get heroes for a team

get_match(match_id: int, force: bool = False)[source]

Get match data

get_pro_matches(match_id: Optional[int] = None, force: bool = False)[source]

Get a list of pro matches

get_live()[source]

Get top currently ongoing live games

get_player(account_id: int, force: bool = False)[source]

Player data

get_pro_players(force: bool = False)[source]

Get a list of pro players

get_player_heroes(player_id: int, force: bool = False)[source]

Get heroes played by a player

get_player_matches(player_id: int, request_parse: bool = False, days: int = 180, force: bool = False)[source]

Matches played by a player

get_player_ratings(player_id: int, force: bool = False)[source]

Player rating history

get_player_rankings(player_id: int, force: bool = False)[source]

Player hero rankings

search_hero(search_key: Optional[str] = None, attack_type: Optional[str] = None, roles: Optional[List[str]] = None)[source]

Search for a hero by name, attack type or roles

search_league(search_key: str)[source]

Search for a league

search_team(search_key: str)[source]

Search for a team by name or tag

search_player(search_key: str)[source]

Search for a player

get_match_fantasy(match_id: int, force: bool = False)[source]

Get Fantasy Points of All Players from a Match

Parameters:

match_id (int or str) – Match ID

Returns:

Fantasy profiles of players from the specified match

Return type:

Dict

get_schema(table_name: Optional[str] = None, force: bool = False)[source]

Get database schema

Parameters:

table_name (str) – Get schema for table_name If None, list the available table names

explorer(sql: str, debug: bool = False)[source]

Submit arbitrary PostgreSQL queries to the database

query(*args, **kwargs)[source]

Submit arbitrary PostgreSQL queries to the database

update_data(frequency: int = 30)[source]

Update core data

Parameters:

frequency (int) –

It is recommended to use utility constants, FREQ_LOW, FREQ_MEDIUM or FREQ_HIGH to specifcy frequency.

FREQ_HIGH: update data that changes frequently

(e.g. teams)

FREQ_MEDIUM: update data that changes with a moderate frequency

(e.g. hero benchmarks)

FREQ_LOW: update data that changes very infrequently

(e.g. heroes)

Module contents

Top-level package for <OPENDOTA/> API.

class opendota.OpenDota(data_dir: Optional[str] = None, api_key: Optional[str] = None, delay: int = 3, fantasy: Optional[dict] = None, api_url: str = 'https://api.opendota.com/api')[source]

Bases: object

<OPENDOTA/> API Interface

Instance of a connection to OpenDota API. All methods return serializable python objects, which are also stored as JSON in the data_dir for future calls. All methods take a boolean argument force which, if True, will fetch the data again even if it is available in the data directory.

Parameters:
  • data_dir (str, (optional)) – Path to data directory for storing responses to API calls The default is ~/dota2.

  • api_key (str, (optional)) – If you have an OpenDota API key The default is None.

  • delay (int, (optional)) – Delay in seconds between two consecutive API calls. It is recommended to keep this at least 3 seconds, to prevent hitting the daily API limit. If you have an API key, this value is ignored. The default is 3.

  • fantasy (dict, (optional)) –

    Fantasy DotA2 Configuration Utility constant FANTASY holds the standard values and is used as default. Keys of the fantasy will override the default values. They must be a subset of the keys of FANTASY.

    Parameters ending with _base are used as base values, while others are used as multipliers. e.g. deaths = -0.3 and deaths_base = 3 results in the calculation as, death_score = 3 + (number_of_deaths * -0.3) If _base parameter is absent, it’s assumed to be 0.

  • api_url (str, (optional)) – URL to OpenDota API. It is recommended to not change this value.

data_dir: str = None
api_key: str = None
delay: int = 3
fantasy: dict = None
api_url: str = 'https://api.opendota.com/api'
request(url: str, *, post: bool = False, data: Optional[dict] = None, filename: Optional[str] = None, force: bool = False) Any[source]

Make a GET or POST request to <OPENDOTA/> API

Parameters:
  • url (str) – API path to query

  • post (bool, (optional)) – Make a POST request. The default is False.

  • data (dict, (optional)) – Query Data. The default is None.

  • filename (str, (optional)) – Save the data to this file. The default is None.

  • force (bool, (optional)) – Force-fetch and overwrite data. The default is False.

Returns:

Result of the API call deserialized as a python object

Return type:

object

get(*args, **kwargs)[source]

Make a GET request to <OPENDOTA/> API.

Calls .request() with post=False

post(*args, **kwargs)[source]

Make a POST request to <OPENDOTA/> API

Calls .request() with post=True

request_parse(match_id: int)[source]

Submit a new parse request

request_status(job_id: int)[source]

Get parse request state

get_constant_names(force: bool = False)[source]

Get an array of available resources

get_constants(resource: Optional[str] = None, force: bool = False)[source]

Get static game data for specified resource(s) (mirrored from the dotaconstants repository)

Parameters:

resource (str or list,) – Name or names of resources

get_heroes(force: bool = False)[source]

Get hero data

get_hero_stats(force: bool = False)[source]

Get stats about hero performance in recent matches

get_hero_benchmarks(hero_id: int, force: bool = False)[source]

Get benchmarks for a hero

get_leagues(force: bool = False)[source]

Get a list of leagues

get_league(league_id: int, force: bool = False)[source]

Get data for a league

get_league_matches(league_id: int, force: bool = False)[source]

Get matches from a league

get_league_teams(league_id: int, force: bool = False)[source]

Get teams from a league

get_teams(force: bool = False)[source]

Get team data

get_team(team_id: int, force: bool = False)[source]

Get data for a team

get_team_matches(team_id: int, force: bool = False)[source]

Get matches for a team

get_team_players(team_id: int, current: bool = True, force: bool = False)[source]

Get players who have played for a team

get_team_heroes(team_id: int, force: bool = False)[source]

Get heroes for a team

get_match(match_id: int, force: bool = False)[source]

Get match data

get_pro_matches(match_id: Optional[int] = None, force: bool = False)[source]

Get a list of pro matches

get_live()[source]

Get top currently ongoing live games

get_player(account_id: int, force: bool = False)[source]

Player data

get_pro_players(force: bool = False)[source]

Get a list of pro players

get_player_heroes(player_id: int, force: bool = False)[source]

Get heroes played by a player

get_player_matches(player_id: int, request_parse: bool = False, days: int = 180, force: bool = False)[source]

Matches played by a player

get_player_ratings(player_id: int, force: bool = False)[source]

Player rating history

get_player_rankings(player_id: int, force: bool = False)[source]

Player hero rankings

search_hero(search_key: Optional[str] = None, attack_type: Optional[str] = None, roles: Optional[List[str]] = None)[source]

Search for a hero by name, attack type or roles

search_league(search_key: str)[source]

Search for a league

search_team(search_key: str)[source]

Search for a team by name or tag

search_player(search_key: str)[source]

Search for a player

get_match_fantasy(match_id: int, force: bool = False)[source]

Get Fantasy Points of All Players from a Match

Parameters:

match_id (int or str) – Match ID

Returns:

Fantasy profiles of players from the specified match

Return type:

Dict

get_schema(table_name: Optional[str] = None, force: bool = False)[source]

Get database schema

Parameters:

table_name (str) – Get schema for table_name If None, list the available table names

explorer(sql: str, debug: bool = False)[source]

Submit arbitrary PostgreSQL queries to the database

query(*args, **kwargs)[source]

Submit arbitrary PostgreSQL queries to the database

update_data(frequency: int = 30)[source]

Update core data

Parameters:

frequency (int) –

It is recommended to use utility constants, FREQ_LOW, FREQ_MEDIUM or FREQ_HIGH to specifcy frequency.

FREQ_HIGH: update data that changes frequently

(e.g. teams)

FREQ_MEDIUM: update data that changes with a moderate frequency

(e.g. hero benchmarks)

FREQ_LOW: update data that changes very infrequently

(e.g. heroes)