slickbet.api¶
Livescore API client for fetching soccer matches and statistics.
Provides dataclasses for teams, odds, fixtures, and historical matches, plus
LivescoreClient for authenticated requests with optional file-based caching.
Exceptions¶
Custom exception for Livescore API errors. |
Classes¶
Enumeration of Livescore API endpoints. |
|
A completed historical match with scores and outcomes. |
|
Client for interacting with the Livescore API. |
|
Represents a soccer match. |
|
Match outcomes (betting results) at different periods. |
|
Match scores at different periods. |
|
Match statistics from the API. |
|
Represents betting odds for a match. |
|
Represents a soccer team. |
|
Detailed team performance statistics from recent matches. |
Module Contents¶
- class slickbet.api.APIEndpoint[source]¶
-
Enumeration of Livescore API endpoints.
- COMPETITIONS_LIST = 'competitions/list.json'¶
- COUNTRIES_LIST = 'countries/list.json'¶
- FIXTURES_LIST = 'fixtures/list.json'¶
- FIXTURES_MATCHES = 'fixtures/matches.json'¶
- LEAGUES_TABLE = 'leagues/table.json'¶
- MATCHES_HISTORY = 'matches/history.json'¶
- MATCHES_STATS = 'matches/stats.json'¶
- TEAMS_HEAD2HEAD = 'teams/head2head.json'¶
- TEAMS_MATCHES = 'teams/matches.json'¶
- class slickbet.api.HistoricalMatch[source]¶
A completed historical match with scores and outcomes.
Per https://live-score-api.com/documentation/reference/15/football_data_history_matches
- date: datetime.datetime¶
- outcomes: MatchOutcome¶
- scores: MatchScores¶
- exception slickbet.api.LivescoreAPIError[source]¶
Bases:
ExceptionCustom exception for Livescore API errors.
- class slickbet.api.LivescoreClient(api_key: str | None = None, api_secret: str | None = None, cache_dir: str | pathlib.Path | None = None, cache_only: bool = False)[source]¶
Client for interacting with the Livescore API.
Uses LIVESCORE_API_KEY and LIVESCORE_API_SECRET environment variables.
- BASE_URL = 'https://livescore-api.com/api-client'¶
- CUP_TO_LEAGUE_MAPPING¶
- api_key¶
- api_secret¶
- cache: slickbet.cache.ApiCache | None¶
- cache_only¶
- enrich_match_with_stats(match: Match) Match[source]¶
Enrich a match object with additional statistics.
- Parameters:
match (Match) – The match to enrich
- Returns:
Match – Match with additional stats (form, standings, H2H, performance)
- get_competitions(country_id: str | None = None) list[dict[str, Any]][source]¶
Get list of available competitions.
- Parameters:
country_id (str or None, optional) – Optional country ID to filter competitions
- Returns:
list[dict[str, Any]] – List of competition dictionaries with id, name, country
- get_countries() list[dict[str, Any]][source]¶
Get list of available countries.
- Returns:
list[dict[str, Any]] – List of country dictionaries with id and name
- get_fixtures_by_date(date: datetime.datetime, competition_id: str | None = None, fetch_all_pages: bool = True) list[Match][source]¶
Get all fixtures for a specific date.
- Parameters:
date (datetime) – The date to fetch fixtures for
competition_id (str or None, optional) – Optional competition ID to filter by
fetch_all_pages (bool, optional) – Whether to fetch all pages (default: True)
- Returns:
list[Match] – List of Match objects
- get_fixtures_list(date: datetime.datetime | None = None, competition_ids: list[str] | None = None, country_id: str | None = None, fetch_all_pages: bool = True) list[Match][source]¶
Get fixtures using the list endpoint with competition_id and country_id filtering.
This endpoint is more efficient for filtering by competition/country as it provides these fields directly, avoiding the need for name-based heuristics.
- Parameters:
date (datetime or None, optional) – The date to fetch fixtures for (defaults to tomorrow)
competition_ids (list[str] or None, optional) – List of competition IDs to filter by
country_id (str or None, optional) – Country ID to filter by
fetch_all_pages (bool, optional) – Whether to fetch all pages (default: True)
- Returns:
list[Match] – List of Match objects
- get_head_to_head(home_team_id: str, away_team_id: str, limit: int = 5) dict[source]¶
Get head-to-head statistics between two teams.
- Parameters:
home_team_id (str) – Home team ID
away_team_id (str) – Away team ID
limit (int, optional) – Number of recent H2H matches to consider
- Returns:
dict – Dictionary with H2H statistics
- get_history(competition_id: str | None = None, team_id: str | None = None, from_date: datetime.datetime | None = None, to_date: datetime.datetime | None = None, page: int = 1) list[HistoricalMatch][source]¶
Get historical match data.
Per https://live-score-api.com/documentation/reference/15/football_data_history_matches
- Parameters:
competition_id (str or None, optional) – Filter by competition (comma-separated for multiple)
team_id (str or None, optional) – Filter by team (comma-separated for multiple)
from_date (datetime or None, optional) – Get matches from this date onwards
to_date (datetime or None, optional) – Get matches until this date
page (int, optional) – Page number for pagination
- Returns:
list[HistoricalMatch] – List of HistoricalMatch objects
- get_match_statistics(match_id: str) MatchStatistics[source]¶
Get statistics for a live or completed match.
Per https://live-score-api.com/documentation/reference/23/match-statistics Statistics are only available after the match has started.
- Parameters:
match_id (str) – The match ID
- Returns:
MatchStatistics – MatchStatistics object with available stats
- get_team_form(team_id: str, limit: int = 5) str[source]¶
Get recent form for a team (last N matches).
- Parameters:
team_id (str) – The team ID
limit (int, optional) – Number of recent matches to consider
- Returns:
str – Form string like “WWDLW” (W=win, D=draw, L=loss)
- get_team_history(team_id: str, limit: int = 10) list[HistoricalMatch][source]¶
Get recent match history for a specific team.
- Parameters:
team_id (str) – The team ID
limit (int, optional) – Maximum number of matches to return
- Returns:
list[HistoricalMatch] – List of HistoricalMatch objects (most recent first)
- get_team_performance_stats(team_id: str, num_matches: int = 10, verbose: bool = False) TeamPerformanceStats[source]¶
Calculate detailed performance statistics for a team from recent matches.
This provides goal-based metrics that improve prediction accuracy: - Goals scored/conceded per game (attack/defense strength) - Clean sheet rate (defensive solidity) - Home/Away specific win rates - Points per game - Match statistics averages (possession, corners, attacks, shots on target)
- Parameters:
team_id (str) – The team ID
num_matches (int, optional) – Number of recent matches to analyze
verbose (bool, optional) – Print debug info about match-statistics availability
- Returns:
TeamPerformanceStats – TeamPerformanceStats with calculated metrics
- get_team_standings(competition_id: str) dict[str, int][source]¶
Get team standings/positions for a competition.
- Parameters:
competition_id (str) – The competition/league ID
- Returns:
dict[str, int] – Dictionary mapping team ID to position
- get_tomorrow_fixtures() list[Match][source]¶
Get all fixtures scheduled for tomorrow.
- Returns:
list[Match] – List of Match objects for tomorrow’s games
- session¶
- class slickbet.api.Match[source]¶
Represents a soccer match.
- away_performance: TeamPerformanceStats | None = None¶
- home_performance: TeamPerformanceStats | None = None¶
- kickoff_time: datetime.datetime¶
- statistics: MatchStatistics | None = None¶
- class slickbet.api.MatchOutcome[source]¶
Match outcomes (betting results) at different periods.
Values are “1” (home win), “X” (draw), or “2” (away win).
- class slickbet.api.MatchScores[source]¶
Match scores at different periods.
- class slickbet.api.MatchStatistics[source]¶
Match statistics from the API.
Per https://live-score-api.com/documentation/reference/23/match-statistics Statistics are only available for live/completed matches, not fixtures. Values are “home:away” format (e.g., “48:52” for possession).
- static calculate_xg_estimate(shots_on_target: int, shots_off_target: int, dangerous_attacks: int, attacks: int, possession: float | None = None) float[source]¶
Calculate estimated xG (Expected Goals) using a model-based approach.
Based on Expected Goals principles from: https://en.wikipedia.org/wiki/Expected_goals
The model assigns probabilities to goal-scoring opportunities based on: 1. Shot quality (on target vs off target) 2. Chance quality (dangerous attacks indicate high-probability chances) 3. Contextual factors (possession, total attacks)
Model inputs (as per Wikipedia): - Shot location/quality: inferred from shots on target (higher xG) - Phase of play: inferred from dangerous attacks (high-quality chances) - Contextual factors: possession and attack volume
- Parameters:
shots_on_target (int) – Number of shots on target (higher probability of goal)
shots_off_target (int) – Number of shots off target (lower probability)
dangerous_attacks (int) – Number of dangerous attacks (high-quality chances)
attacks (int) – Total number of attacks (context factor)
possession (float or None, optional) – Possession percentage (0-100), used to adjust shot quality
- Returns:
float – Estimated xG value (sum of shot probabilities)
- has_data() bool[source]¶
Check if this MatchStatistics object has any meaningful data.
- Returns:
bool – True if at least one statistic field has data
- static parse_float_stat(value: str | None) tuple[float, float] | None[source]¶
Parse
home:awayformat to a float tuple (for xG).- Parameters:
value (str or None) – Stat string like
"1.2:0.8".- Returns:
tuple[float, float] or None –
(home, away)values, or None if unparseable.
- class slickbet.api.TeamPerformanceStats[source]¶
Detailed team performance statistics from recent matches. Used to improve betting predictions with goal-based metrics.
Based on: https://live-score-api.com/documentation/reference/27/getting-teams-last-matches