opendota package
Submodules
opendota.cli module
Console Script for <OPENDOTA/> API
@author: Hrishikesh Terdalkar
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 argumentforce
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 ofFANTASY
.Parameters ending with
_base
are used as base values, while others are used as multipliers. e.g.deaths = -0.3
anddeaths_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
- 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_team_players(team_id: int, current: bool = True, force: bool = False)[source]
Get players who have played for a team
- get_pro_matches(match_id: Optional[int] = None, force: bool = False)[source]
Get a list of pro matches
- get_player_matches(player_id: int, request_parse: bool = False, days: int = 180, force: bool = False)[source]
Matches played by a player
- 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
- 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
- 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 argumentforce
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 ofFANTASY
.Parameters ending with
_base
are used as base values, while others are used as multipliers. e.g.deaths = -0.3
anddeaths_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
- 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_team_players(team_id: int, current: bool = True, force: bool = False)[source]
Get players who have played for a team
- get_pro_matches(match_id: Optional[int] = None, force: bool = False)[source]
Get a list of pro matches
- get_player_matches(player_id: int, request_parse: bool = False, days: int = 180, force: bool = False)[source]
Matches played by a player
- 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
- 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
- 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)