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: A 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: 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: 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: 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: 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: 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: A LeagueTable
object.
-
get_prev_response
()¶ Returns information about the most recent response.
Returns: A dict containing information about the most recent response.
-
get_team
(team_id=None, team_name=None)¶ Given an ID, returns a Team object for the team associated with the ID. If no ID is supplied, checks if name is supplied. Database is queried using the team name and the first result in the response is returned. If both ID and name are supplied, ID will be evaluated and name will be ignored.
Sends one request to api.football-data.org if fetching team by ID; two requests if fetching team by name.
Parameters: - team_id (integer) – The team ID. Default
None
. - team_name (string) – The team name. Default
None
.
Returns: A
Team
object on success, orNone
if nomatches are found for the given team_name or ID.
- team_id (integer) – The team ID. Default
-
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: A list of Fixture
objects for the specified 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: A list of Player
objects based on players 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: A dict with team ID as keys and team name as values. 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: A list of Fixture
objects.
-
get_league_table
()¶ Return the league table for this competition.
Sends one request to api.football-data.org.
Returns: 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: 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: 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: A list of Player
objects.
-