API¶
For every function that sends a HTTP request, an HTTPError
is raised whenever the response status code is 4XX
or 5XX
which signifies that something went wrong between pyfootball sending the API a request and the API giving a response. If you believe this to be an issue with pyfootball itself, please see Support for more information.
Football¶
This class serves as the driver/entry point for this library.
-
class
pyfootball.football.
Football
(api_key=None)¶ -
__init__
(api_key=None)¶ Takes either an api_key as a keyword argument or tries to access an environmental variable
PYFOOTBALL_API_KEY
, then uses the key to send a test request to make sure that it’s valid. The api_key kwarg takes precedence over the envvar.Sends one request to api.football-data.org.
Parameters: api_key (string) – The user’s football-data.org API key.
-
get_all_competitions
()¶ Returns a list of Competition objects representing the current season’s competitions.
Sends one request to api.football-data.org.
Returns: comp_list: List of Competition objects.
-
get_all_fixtures
()¶ Returns a list of all Fixture objects in the specified time frame. Defaults to the next 7 days or “n7”. TODO: Include timeFrameStart and timeFrameEnd, and filter for specifying time frame.
Sends one request to api.football-data.org.
Returns: fixture_list: A list of Fixture objects.
-
get_comp_fixtures
(comp_id)¶ Given an ID, returns a list of Fixture objects associated with the given competition.
Sends one request to api.football-data.org.
Parameters: comp_id (integer) – The competition ID. Returns: fixture_list: A list of Fixture objects.
-
get_competition
(comp_id)¶ Returns a Competition object associated with the competition ID.
Sends one request to api.football-data.org.
Parameters: comp_id (integer) – The competition ID. Returns: Competition: The Competition object.
-
get_competition_teams
(comp_id)¶ Given an ID, returns a list of Team objects associated with the given competition.
Sends one request to api.football-data.org.
Parameters: comp_id (integer) – The competition ID. Returns: team_list: A list of Team objects.
-
get_fixture
(fixture_id)¶ Returns a Fixture object associated with the given ID. The response includes a head-to-head between teams; this will be implemented in the near future.
Sends one request to api.football-data.org.
Parameters: fixture_id (integer) – The fixture ID. Returns: Fixture: A Fixture object.
-
get_league_table
(comp_id)¶ Given a competition ID, returns a LeagueTable object for the league table associated with the competition.
Sends one request to api.football-data.org.
Parameters: comp_id (integer) – The competition ID. Returns: LeagueTable: A LeagueTable object.
-
get_prev_response
()¶ Returns information about the most recent response.
Returns: prev_response: Information about the most recent response.
-
get_team
(team_id)¶ Given an ID, returns a Team object for the team associated with the ID.
Sends one request to api.football-data.org.
Parameters: team_id (integer) – The team ID. Returns: Team: A Team object.
-
get_team_fixtures
(team_id)¶ Given a team ID, returns a list of Fixture objects associated with the team.
Sends one request to api.football-data.org.
Parameters: team_id (integer) – The team ID. Returns: fixture_list: A list of Fixture objects for the team.
-
get_team_players
(team_id)¶ Given a team ID, returns a list of Player objects associated with the team.
Sends one request to api.football-data.org.
Parameters: team_id (integer) – The team ID. Returns: player_list: A list of Player objects in the specified team.
-
search_teams
(team_name)¶ Given a team name, queries the database for matches and returns a dictionary containing key-value pairs of their team IDs and team names.
Sends one request to api.football-data.org.
Parameters: team_name (string) – The partial or full team name. Returns: matches: A dict with team ID as keys and team name as values. Returns: None
: If no matches are found for the given team_name.
-
Competition¶
-
class
pyfootball.models.competition.
Competition
(data)¶ -
get_fixtures
()¶ Return a list of Fixture objects representing the fixtures in this competition for the current season.
Sends one request to api.football-data.org.
Returns: fixture_list: A list of Fixture objects.
-
get_league_table
()¶ Return the league table for this competition.
Sends one request to api.football-data.org.
Returns: LeagueTable: A LeagueTable object.
-
get_teams
()¶ Return a list of Team objects representing the teams in this competition for the current season.
Sends one request to api.football-data.org.
Returns: team_list: A list of Team objects.
-
Team¶
-
class
pyfootball.models.team.
Team
(data)¶ -
get_fixtures
()¶ Return a list of Fixture objects representing this season’s fixtures for the current team.
Sends one request to api.football-data.org.
Returns: fixture_list: A list of Fixture objects.
-
get_players
()¶ Return a list of Player objects representing players on the current team.
Sends one request to api.football-data.org.
Returns: player_list: A list of Player objects.
-