### Install fotmob-api using pip Source: https://github.com/c-roensholt/fotmob-api/blob/main/README.md Install the package from PyPi using pip. ```bash pip install fotmob-api ``` -------------------------------- ### Install latest development version Source: https://github.com/c-roensholt/fotmob-api/blob/main/README.md Install the latest development version directly from the GitHub repository. ```bash pip install git+git@github.com:C-Roensholt/fotmob-api.git ``` -------------------------------- ### Initialize FotMob API and Get All Leagues Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Initializes the FotMob API client and retrieves a list of all available leagues. This is a prerequisite for fetching data for specific leagues. ```python from fotmob_api import FotmobAPI import pandas as pd from plottable.cmap import normed_cmap from plottable import Table, ColumnDefinition import matplotlib import matplotlib.pyplot as plt # Initialize client client = FotmobAPI() # Get all leagues all_leagues = client.get_league_all() # Create dataframe for country leagues df_country_leagues = pd.json_normalize(all_leagues["countries"], record_path=["leagues"], meta=["ccode", "name", "localizedName"], record_prefix="league") df_country_leagues.head() ``` -------------------------------- ### Get Fixtures for a League and Season Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetch all fixtures for a given league and season, including status, scores, and team information. Useful for match lookups. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() fixtures = client.get_fixtures(id=47, season="2023/2024") df = pd.json_normalize(fixtures, max_level=1, sep="_") # Build a match description and parse dates df["description"] = df["home_name"] + " - " + df["away_name"] df["date"] = pd.to_datetime(df["status_utcTime"]).dt.strftime("%Y-%m-%d") # Look up a specific match ID match_id = df[ (df["description"] == "Chelsea - Man City") & (df["date"] == "2023-11-12") ]["id"].item() print(match_id) # e.g. 4193490 print(df[["description", "date", "status_scoreStr"]].head()) # description date status_scoreStr # 0 Burnley - Man City 2023-08-11 0 - 3 # 1 Arsenal - Nottm Forest 2023-08-12 2 - 1 ``` -------------------------------- ### Initialize FotMob API and Get League ID Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/player_stats.ipynb Initializes the FotMobAPI client and retrieves the league ID for the 'Premier League' in 'England'. Requires the 'fotmob_api' and 'pandas' libraries. ```python from fotmob_api import FotmobAPI import pandas as pd # Initialize client client = FotmobAPI() # Get fixtures for a specific league # get league id all_leagues = client.get_league_all() df_country_leagues = pd.json_normalize(all_leagues["countries"], record_path=["leagues"], meta=["ccode", "name", "localizedName"], record_prefix="league") league_id = df_country_leagues[(df_country_leagues["leaguename"]=="Premier League") & (df_country_leagues["name"]=="England")]["leagueid"].item() # Get league table in order to get team ids league_table = client.get_league_table(league_id=league_id) team_ids = {team["name"]: team["id"] for team in league_table[0]["data"]["table"]["all"]} team_ids ``` -------------------------------- ### Get Simple Player Data Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches lightweight profile information for a player, including name, current club, and nationality. Requires player ID. ```python from fotmob_api import FotmobAPI client = FotmobAPI() player = client.get_player_data_simple(player_id=954) # Mohamed Salah print(player["name"], player["primaryTeam"]["teamName"]) ``` -------------------------------- ### Get Match Media Content Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves media content such as highlights and press conference links for a given match ID and country code. ```python from fotmob_api import FotmobAPI client = FotmobAPI() media = client.get_match_media(match_id=4193490, ccode="ENG") print(media.keys()) # dict_keys(['media', ...]) ``` -------------------------------- ### Initialize FotMob API and Get League ID Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/team_stats.ipynb Initializes the FotMob API client and retrieves the league ID for a specified league and country. Requires the 'fotmob_api' and 'pandas' libraries. ```python from fotmob_api import FotmobAPI import pandas as pd # Get Premier League stats for Aston Villa for 2023/2024 season country = "England" league_name = "Premier League" team_name = "Aston Villa" season_name = "2023/2024" # Initialize client client = FotmobAPI() # Get fixtures for a specific league # get league id all_leagues = client.get_league_all() df_country_leagues = pd.json_normalize(all_leagues["countries"], record_path=["leagues"], meta=["ccode", "name", "localizedName"], record_prefix="league") league_id = df_country_leagues[(df_country_leagues["leaguename"]==league_name) & (df_country_leagues["name"]==country)]["leagueid"].item() ``` -------------------------------- ### Get Matches for a Specific Date Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieve all matches across all leagues for a given date. This can be optionally filtered by country code and timezone. ```python from fotmob_api import FotmobAPI client = FotmobAPI() ``` -------------------------------- ### Get League Table with xG Stats Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetch league standings, including standard and xG-enhanced tables. Useful for analyzing team performance beyond basic metrics. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() league_id = 47 # Premier League league_table = client.get_league_table(league_id=league_id) # Standard standings df_table = pd.DataFrame(league_table[0]["data"]["table"]["all"]) # xG-enhanced standings df_table_xg = pd.DataFrame(league_table[0]["data"]["table"]["xg"]) print(df_table_xg[["name", "played", "pts", "xg", "xgConceded", "xgDiff", "xPoints"]].head()) # name played pts xg xgConceded xgDiff xPoints # 0 Arsenal 23 49 45.06 17.8359 -1.9383 48.220737 # 1 Manchester City 22 49 44.28 21.8244 -9.7218 44.761720 # Team IDs from the table (useful for other API calls) team_ids = {team["name"]: team["id"] for team in league_table[0]["data"]["table"]["all"]} # {'Manchester City': 8456, 'Liverpool': 8650, 'Arsenal': 9825, ...} ``` -------------------------------- ### Get Full Player Data Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves comprehensive player profile data, including career history and recent matches. Requires player ID. ```python from fotmob_api import FotmobAPI client = FotmobAPI() player = client.get_player_data(player_id=954) # Mohamed Salah print(player.keys()) # dict_keys(['id', 'name', 'primaryTeam', 'career', 'recentMatches', ...]) ``` -------------------------------- ### Get League Metadata Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieve basic metadata for a specific league using its ID. This includes season stat links and tournament IDs. ```python client = FotmobAPI() league_info = client.get_league(league_id=47) # Premier League # Extract tournament IDs keyed by season name tournament_ids = { t["Name"]: t["TournamentId"] for t in league_info["stats"]["seasonStatLinks"] } print(tournament_ids) # {'2023/2024': 12345, '2022/2023': 11234, ...} ``` -------------------------------- ### Get Team Squad Details Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/player_stats.ipynb Retrieves squad details for a specified team ('Liverpool') using the previously obtained team ID. This helps in getting player IDs from the squad list. Requires the 'pandas' library for DataFrame manipulation. ```python # Get squad details for a team in order to get player id team_name = "Liverpool" team_info = client.get_team(team_id=[team_ids[team_name]]) df_squad = pd.concat([pd.DataFrame(squad[1]) for squad in team_info["squad"]]) df_squad.head() ``` -------------------------------- ### Get Match Betting Odds Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches betting odds for a specific match from various providers. Requires match ID and country code. ```python from fotmob_api import FotmobAPI client = FotmobAPI() odds = client.get_match_odds(match_id=4193490, ccode="ENG") print(odds) ``` -------------------------------- ### Get Player News Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves the latest news articles related to a specific player. Requires player ID and language code. ```python from fotmob_api import FotmobAPI client = FotmobAPI() news = client.get_player_news(player_id=954, language="en-GB") for article in news[:3]: print(article["title"]) ``` -------------------------------- ### Get Team Season Statistics Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/team_stats.ipynb Retrieves detailed season statistics for a specific team within a given season. It first gets league information to find the correct tournament ID, then fetches team stats and normalizes them into a Pandas DataFrame. ```python # Get team stats league_info = client.get_league(league_id=league_id) tournament_ids = {tournament["Name"]: tournament["TournamentId"] for tournament in league_info["stats"]["seasonStatLinks"]} team_season_stats = client.get_team_season_stats(team_id=team_ids[team_name], tournament_id=tournament_ids[season_name]) df_team_season_stats = pd.json_normalize(team_season_stats["tournamentStats"]["TopStats"], record_path="StatList", meta=["Title", "Subtitle"], errors="ignore") df_team_season_stats.head() ``` -------------------------------- ### Get Detailed Match Data and Stats Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches detailed match data, including period stats, shot maps with xG, and player events. This is the primary method for in-depth match analysis. Requires pandas for data normalization. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() match_id = 4193490 # Chelsea vs Man City details = client.get_match_details(match_id=match_id) # Overall match stats (possession, xG, shots, etc.) df_stats = pd.json_normalize( details["content"]["stats"]["Periods"]["All"]["stats"], record_path=["stats"], meta=["title"], meta_prefix="meta_" ) df_stats[["home_stats", "away_stats"]] = pd.DataFrame( df_stats["stats"].tolist(), index=df_stats.index ) print(df_stats[["meta_title", "title", "home_stats", "away_stats"]].head(5)) # meta_title title home_stats away_stats # 0 Top stats Ball possession 45 55 # 1 Top stats Expected goals (xG) 2.95 2.88 # 2 Top stats Total shots 17 15 # Shot map with xG values df_shots = pd.DataFrame(details["content"]["shotmap"]["shots"]) print(df_shots[["eventType", "playerName", "x", "y", "min", "expectedGoals"]].head()) # eventType playerName x y min expectedGoals # 0 AttemptSaved Reece James 91.4 19.234904 1 0.030917 # 1 AttemptSaved Cole Palmer 93.1 21.056561 12 0.038994 ``` -------------------------------- ### Get All Leagues and Find Premier League ID Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetch all available leagues and organize them into a pandas DataFrame. This is useful for discovering league IDs needed for other API calls. ```python from fotmob_api import FotmobAPI import pandas as pd client = FotmobAPI() all_leagues = client.get_league_all() # Flatten to a DataFrame: one row per league df = pd.json_normalize( all_leagues["countries"], record_path=["leagues"], meta=["ccode", "name", "localizedName"], record_prefix="league" ) # Find the Premier League ID league_id = df[ (df["leaguename"] == "Premier League") & (df["name"] == "England") ]["leagueid"].item() print(league_id) # e.g. 47 ``` -------------------------------- ### Get Transfers Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches recent transfer activity. Can be filtered for top transfers and paginated. Requires boolean for showTop and page number. ```python from fotmob_api import FotmobAPI client = FotmobAPI() # Top transfers, page 1 transfers = client.get_transfers(showTop=True, page=1) print(transfers.keys()) # Browse more transfers page2 = client.get_transfers(showTop=False, page=2) ``` -------------------------------- ### Get League of the Week Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieve the highlighted league of the week for a specified country code. ```python client = FotmobAPI() lotw = client.get_league_of_the_week(ccode="ENG") print(lotw) # {'id': 47, 'name': 'Premier League', ...} ``` -------------------------------- ### Get User Location Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns geolocation information based on the caller's IP address. Useful for determining the appropriate country code. ```python from fotmob_api import FotmobAPI client = FotmobAPI() location = client.get_my_location() print(location) # {'ccode': 'ENG', 'country': 'United Kingdom', ...} ``` -------------------------------- ### Get Matches for a Specific Date Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches matches for a given date and country code. Omitting the date retrieves today's matches. ```python matches = client.get_matches(date="20231112", ccode="ENG") today = client.get_matches() print(matches.keys()) # dict_keys(['leagues', 'date', ...]) ``` -------------------------------- ### Get Match Information Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves high-level information for a specific match using its ID. Useful for quick overviews of teams, scores, and basic events. ```python from fotmob_api import FotmobAPI client = FotmobAPI() match_id = 4193490 # Chelsea vs Man City, 12 Nov 2023 match = client.get_match(match_id=match_id) print(match["general"]["homeTeam"]["name"]) # Chelsea print(match["general"]["awayTeam"]["name"]) # Man City ``` -------------------------------- ### Get Team of the Week Data Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves the top-rated players for a specific league and round. Requires league ID and round ID. ```python from fotmob_api import FotmobAPI client = FotmobAPI() totw = client.get_team_of_the_week(league_id=47, round_id=23, season="2023/2024") for player in totw["players"]: print(player["name"], player["rating"]) ``` -------------------------------- ### Get Player Statistics Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/player_stats.ipynb Fetches detailed statistics for a specific player ('Mohamed Salah') for a given league and season ('2023/2024'). Requires the player's ID obtained from the squad details and the league ID. Uses pandas for normalizing the JSON response. ```python # Get stats from a player player_name = "Mohamed Salah" player_id = df_squad[df_squad["name"] == player_name]["id"].item() players_stats = client.get_player_stats(player_id=player_id, league_id=league_id, season="2023/2024") df_player_stats = pd.json_normalize(players_stats["statsSection"], record_path=["items", ["items"]], meta="title", meta_prefix="meta_") df_player_stats.head() ``` -------------------------------- ### Get Team Historical League Table Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches historical league table finishes and performance data for a team across past seasons using its team ID. ```python from fotmob_api import FotmobAPI client = FotmobAPI() history = client.get_team_historical_table(team_id=8456) # Manchester City print(history.keys()) ``` -------------------------------- ### Get Team Information and Squad Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves general team information and a full squad list, including player IDs, nationalities, and injury status. Uses pandas for squad data normalization. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() team_id = 8650 # Liverpool team_info = client.get_team(team_id=team_id, ccode="ENG") # Flatten all squad groups into one DataFrame df_squad = pd.concat([pd.DataFrame(squad[1]) for squad in team_info["squad"]]) print(df_squad[["id", "name", "cname", "role", "isInjured"]].head()) # id name cname role isInjured # 0 319784 Alisson Becker Brazil goalkeepers NaN # 0 171698 Joel Matip Cameroon defenders True ``` -------------------------------- ### Get Team IDs from League Table Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/team_stats.ipynb Fetches the league table to extract team IDs, mapping team names to their corresponding IDs. This is a prerequisite for fetching team-specific data. ```python # Get league table in order to get team ids league_table = client.get_league_table(league_id=league_id) team_ids = {team["name"]: team["id"] for team in league_table[0]["data"]["table"]["all"]} team_ids ``` -------------------------------- ### Get Team Season Statistics Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves season-level statistics for a team within a specific tournament, such as top scorers and assist leaders. Requires pandas for data normalization. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() team_id = 10252 # Aston Villa tournament_id = 12345 # Obtained from get_league() -> stats.seasonStatLinks stats = client.get_team_season_stats(team_id=team_id, tournament_id=tournament_id) df = pd.json_normalize( stats["tournamentStats"]["TopStats"], record_path="StatList", meta=["Title", "Subtitle"], errors="ignore" ) print(df[["ParticipantName", "StatValue", "Title", "Subtitle"]].head()) # ParticipantName StatValue Title Subtitle # 0 Ollie Watkins 11.0 Top scorer Penalty goals # 1 Leon Bailey 7.0 Top scorer Penalty goals # 3 Ollie Watkins 10.0 Assists Expected assist (xA) ``` -------------------------------- ### Get Team of the Week Rounds Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves all rounds in a season for which a 'Team of the Week' has been awarded in a given league. Requires league ID and season year. ```python from fotmob_api import FotmobAPI client = FotmobAPI() rounds = client.get_team_of_the_week_rounds(league_id=47, season="2023/2024") print([r["roundId"] for r in rounds["rounds"]]) # [1, 2, 3, ..., 23] ``` -------------------------------- ### Get Player Season Stats Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches a player's season-level statistical breakdown for a specific league and season. Requires player ID, league ID, and season. Results can be normalized into a pandas DataFrame. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() player_id = 954 # Mohamed Salah league_id = 47 # Premier League stats = client.get_player_stats(player_id=player_id, league_id=league_id, season="2023/2024") df = pd.json_normalize( stats["statsSection"], record_path=["items", ["items"]], meta="title", meta_prefix="meta_" ) print(df[["title", "statValue", "per90", "percentileRank"]].head()) # title statValue per90 percentileRank # 0 Goals 14 0.722892 100.0 # 1 xG 14.27 0.737050 100.0 # 2 xGOT 14.49 0.748327 100.0 # 3 Penalty goals 4 0.206540 96.3 # 4 xG excl. penalty 9.54 0.492795 100.0 ``` -------------------------------- ### Initialize FotMobAPI Client Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Create an instance of the FotmobAPI client. You can use the default rate limit or specify a custom one. ```python from fotmob_api import FotmobAPI # Default: 6 requests per second client = FotmobAPI() ``` ```python # Custom rate limit client = FotmobAPI(requests_per_sec=3) ``` -------------------------------- ### Initializing the Client Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Creates a FotmobAPI instance with optional rate limiting. All API methods are available on this object. ```APIDOC ## Initializing the Client Creates a `FotmobAPI` instance with optional rate limiting. All API methods are available on this object. ```python from fotmob_api import FotmobAPI # Default: 6 requests per second client = FotmobAPI() # Custom rate limit client = FotmobAPI(requests_per_sec=3) ``` ``` -------------------------------- ### Initialize FotMob API and Fetch League Data Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/match_stats.ipynb Initializes the FotMob API client and retrieves all leagues to find the ID for a specific league, like the Premier League in England. This is a prerequisite for fetching fixtures. ```python from fotmob_api import FotmobAPI import pandas as pd # Initialize client client = FotmobAPI() # Get fixtures for a specific league # get league id all_leagues = client.get_league_all() df_country_leagues = pd.json_normalize(all_leagues["countries"], record_path=["leagues"], meta=["ccode", "name", "localizedName"], record_prefix="league") league_id = df_country_leagues[(df_country_leagues["leaguename"]=="Premier League") & (df_country_leagues["name"]=="England")]["leagueid"].item() # get fixtures fixtures = client.get_fixtures(id=league_id, season="2023/2024") df_fixtures = pd.json_normalize(fixtures, max_level=1, sep="_") df_fixtures.head() ``` -------------------------------- ### Fetch Premier League Table Data Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Fetches the league table data for the Premier League by first identifying its league ID from the list of all leagues. The expected goals data is then extracted and displayed. ```python # Get Premier League league id league_id = df_country_leagues[(df_country_leagues["leaguename"]=="Premier League") & (df_country_leagues["name"]=="England")]["leagueid"].item() # Get table from Premier League league_table = client.get_league_table(league_id=league_id) table = league_table[0]["data"]["table"] df_table_xg = pd.DataFrame(table["xg"]) df_table_xg.head() ``` -------------------------------- ### Display Match Shot Details Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/match_stats.ipynb Displays the first few rows of the match shots dataframe, including event type, player name, shot coordinates, and expected goals. ```python # show shots df_match_shots[["eventType", "playerName", "x", "y", "min", "shotType", "situation", "expectedGoals", "expectedGoalsOnTarget"]].head() ``` -------------------------------- ### get_player_data_simple Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches lightweight profile information for a player, including their name, current club, nationality, and a brief biography. ```APIDOC ## get_player_data_simple ### Description Returns lightweight profile information for a player — name, current club, nationality, and basic bio. ### Parameters #### Query Parameters - **player_id** (int) - Required - The unique identifier for the player. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() player = client.get_player_data_simple(player_id=954) # Mohamed Salah ``` ### Response #### Success Response (200) - **name** (str) - The player's name. - **primaryTeam** (object) - Information about the player's current team, including `teamName`. ``` -------------------------------- ### get_fixtures Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves all fixtures (matches) for a given league and season, with status, scores, and team information. ```APIDOC ## get_fixtures Retrieves all fixtures (matches) for a given league and season, with status, scores, and team information. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() fixtures = client.get_fixtures(id=47, season="2023/2024") df = pd.json_normalize(fixtures, max_level=1, sep="_") # Build a match description and parse dates df["description"] = df["home_name"] + " - " + df["away_name"] df["date"] = pd.to_datetime(df["status_utcTime"]).dt.strftime("%Y-%m-%d") # Look up a specific match ID match_id = df[ (df["description"] == "Chelsea - Man City") & (df["date"] == "2023-11-12") ]["id"].item() print(match_id) # e.g. 4193490 print(df[["description", "date", "status_scoreStr"]].head()) # description date status_scoreStr # 0 Burnley - Man City 2023-08-11 0 - 3 # 1 Arsenal - Nottm Forest 2023-08-12 2 - 1 ``` ``` -------------------------------- ### Display Overall Match Stats Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/match_stats.ipynb Shows the first 9 rows of the overall match statistics dataframe. This includes metrics like ball possession, expected goals, and shots. ```python # show overall match stats df_match_stats.head(9) ``` -------------------------------- ### get_league_all Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns a complete list of all leagues available on FotMob, organized by country. The response includes league IDs, names, page URLs, and country codes. ```APIDOC ## get_league_all Returns a complete list of all leagues available on FotMob, organized by country. The response includes league IDs, names, page URLs, and country codes — useful for discovering IDs needed by other methods. ```python from fotmob_api import FotmobAPI import pandas as pd client = FotmobAPI() all_leagues = client.get_league_all() # Flatten to a DataFrame: one row per league df = pd.json_normalize( all_leagues["countries"], record_path=["leagues"], meta=["ccode", "name", "localizedName"], record_prefix="league" ) # Find the Premier League ID league_id = df[ (df["leaguename"] == "Premier League") & (df["name"] == "England") ]["leagueid"].item() print(league_id) # e.g. 47 # leagueid leaguename ccode name # 0 10175 Super Cup ALB Albania # 1 260 Superiore ALB Albania ``` ``` -------------------------------- ### Process Fixtures and Extract Match ID Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/match_stats.ipynb Processes the fetched fixtures to create a descriptive column and extracts the match ID for a specific game on a given date. This ID is used to fetch detailed match information. ```python # Create match description column df_fixtures["description"] = ( df_fixtures["home_name"] + " - " + df_fixtures["away_name"]) df_fixtures["date"] = pd.to_datetime(df_fixtures["status_utcTime"]).dt.strftime('%Y-%m-%d') # Get match id for Chelsea - Man City on 12th of November match_id = df_fixtures[(df_fixtures["description"] == "Chelsea - Man City") & (df_fixtures["date"] == "2023-11-12")]["id"].item() # Get match details match_details = client.get_match_details(match_id=match_id) ``` -------------------------------- ### Create and Render League Table Plot Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Initializes a matplotlib figure and axes, then creates a Table object using the prepared DataFrame and column definitions. Finally, it sets the main title and subtitle for the plot. ```python # Plot table fig, ax = plt.subplots(figsize=(12, 12)) table_plot = Table(df=df_table_xg_plot, column_definitions=col_def, ax=ax, textprops={"fontsize": 12}) fig.suptitle("Premier League Standings", y=0.95, fontweight="bold", fontsize=24) ax.set_title("Expected Goals Table - 2023/2024", fontweight="regular", fontsize=18) ``` -------------------------------- ### get_match_details Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns detailed match data including period-level stats, shot maps with xG, and player-level events. This is the primary method for match analysis. ```APIDOC ## get_match_details ### Description Returns detailed match data including period-level stats, shot maps with xG, and player-level events. The primary method for match analysis. ### Method `get_match_details` ### Parameters #### Path Parameters - **match_id** (int) - Required - The unique identifier for the match. ### Request Example ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() match_id = 4193490 details = client.get_match_details(match_id=match_id) ``` ### Response #### Success Response (200) - **content.stats.Periods.All.stats** (list) - Contains all match statistics. - **content.shotmap.shots** (list) - Contains data for the shot map. ### Response Example ```json { "content": { "stats": { "Periods": { "All": { "stats": [ { "title": "Ball possession", "stats": [{"home_stats": 45, "away_stats": 55}] } ] } } }, "shotmap": { "shots": [ { "eventType": "AttemptSaved", "playerName": "Reece James", "x": 91.4, "y": 19.234904, "min": 1, "expectedGoals": 0.030917 } ] } } } ``` ``` -------------------------------- ### get_match Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns high-level information about a specific match, including teams, score, status, and a basic event summary. ```APIDOC ## get_match ### Description Returns high-level information about a specific match — teams, score, status, and basic event summary. ### Method `get_match` ### Parameters #### Path Parameters - **match_id** (int) - Required - The unique identifier for the match. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() match_id = 4193490 match = client.get_match(match_id=match_id) ``` ### Response #### Success Response (200) - **general.homeTeam.name** (str) - Name of the home team. - **general.awayTeam.name** (str) - Name of the away team. ### Response Example ```json { "general": { "homeTeam": {"name": "Chelsea"}, "awayTeam": {"name": "Man City"} } } ``` ``` -------------------------------- ### get_team Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns squad and general information for a specific team, including the full squad list with player IDs, nationalities, and injury status. ```APIDOC ## get_team ### Description Returns squad and general information for a specific team, including the full squad list with player IDs, nationalities, and injury status. ### Method `get_team` ### Parameters #### Path Parameters - **team_id** (int) - Required - The unique identifier for the team. - **ccode** (str) - Optional - Country code for filtering. ### Request Example ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() team_id = 8650 team_info = client.get_team(team_id=team_id, ccode="ENG") ``` ### Response #### Success Response (200) - **squad** (list) - A list of squad groups, each containing player information. ### Response Example ```json { "squad": [ ["goalkeepers", [ {"id": 319784, "name": "Alisson Becker", "cname": "Brazil", "role": "goalkeepers", "isInjured": false} ]], ["defenders", [ {"id": 171698, "name": "Joel Matip", "cname": "Cameroon", "role": "defenders", "isInjured": true} ]] ] } ``` ``` -------------------------------- ### Define League Table Columns and Plot Data Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Selects relevant columns for a league table plot and prepares the DataFrame. This is useful for visualizing team statistics. ```python columns = ["shortName", "played", "wins", "draws", "losses", "pts","xPoints", "xg","xgConceded", "xgDiff", "xPointsDiff", "idx"] column_names = [] df_table_xg_plot = df_table_xg[columns].set_index("idx").round(1) ``` -------------------------------- ### get_player_data Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves comprehensive player profile data, encompassing career history, recent match performance, and detailed biographical information. ```APIDOC ## get_player_data ### Description Returns full player profile including career history, recent matches, and detailed biographical data. ### Parameters #### Query Parameters - **player_id** (int) - Required - The unique identifier for the player. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() player = client.get_player_data(player_id=954) # Mohamed Salah ``` ### Response #### Success Response (200) - Returns a dictionary containing detailed player information, including `id`, `name`, `primaryTeam`, `career`, `recentMatches`, and other biographical data. ``` -------------------------------- ### get_match_media Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns media content such as highlights and press conference links for a specific match. ```APIDOC ## get_match_media ### Description Returns media content (highlights, press conference links, etc.) for a specific match. ### Method `get_match_media` ### Parameters #### Path Parameters - **match_id** (int) - Required - The unique identifier for the match. - **ccode** (str) - Optional - Country code for filtering. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() media = client.get_match_media(match_id=4193490, ccode="ENG") ``` ### Response #### Success Response (200) - **media** (list) - A list of media items available for the match. ### Response Example ```json { "media": [ { "type": "highlights", "url": "http://example.com/highlight.mp4" } ] } ``` ``` -------------------------------- ### get_matches Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns all matches across all leagues for a given date, optionally filtered by country code and timezone. ```APIDOC ## get_matches Returns all matches across all leagues for a given date, optionally filtered by country code and timezone. ```python from fotmob_api import FotmobAPI client = FotmobAPI() ``` -------------------------------- ### get_league Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches basic metadata for a specific league by its ID, including season stat links and tournament IDs needed for season-level queries. ```APIDOC ## get_league Fetches basic metadata for a specific league by its ID, including season stat links and tournament IDs needed for season-level queries. ```python client = FotmobAPI() league_info = client.get_league(league_id=47) # Premier League # Extract tournament IDs keyed by season name tournament_ids = { t["Name"]: t["TournamentId"] for t in league_info["stats"]["seasonStatLinks"] } print(tournament_ids) # {'2023/2024': 12345, '2022/2023': 11234, ...} ``` ``` -------------------------------- ### get_league_table Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns the full league standings table for a given league, including optional advanced xG stats for specified teams. ```APIDOC ## get_league_table Returns the full league standings table for a given league, including optional advanced xG stats for specified teams. ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() league_id = 47 # Premier League league_table = client.get_league_table(league_id=league_id) # Standard standings df_table = pd.DataFrame(league_table[0]["data"]["table"]["all"]) # xG-enhanced standings df_table_xg = pd.DataFrame(league_table[0]["data"]["table"]["xg"]) print(df_table_xg[["name", "played", "pts", "xg", "xgConceded", "xgDiff", "xPoints"]].head()) # name played pts xg xgConceded xgDiff xPoints # 0 Arsenal 23 49 45.06 17.8359 -1.9383 48.220737 # 1 Manchester City 22 49 44.28 21.8244 -9.7218 44.761720 # Team IDs from the table (useful for other API calls) team_ids = {team["name"]: team["id"] for team in league_table[0]["data"]["table"]["all"]} # {'Manchester City': 8456, 'Liverpool': 8650, 'Arsenal': 9825, ...} ``` ``` -------------------------------- ### Display Figure Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Renders the matplotlib figure object, showing the generated league table plot. ```python Result:
``` -------------------------------- ### get_transfers Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves recent football transfer activity, with options for pagination and filtering for top transfers. ```APIDOC ## get_transfers ### Description Returns recent transfer activity across football, with optional pagination and filtering for top transfers. ### Parameters #### Query Parameters - **showTop** (bool) - Optional - If true, shows only top transfers. Defaults to false. - **page** (int) - Optional - The page number for pagination. Defaults to 1. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() # Top transfers, page 1 transfers = client.get_transfers(showTop=True, page=1) # Browse more transfers page2 = client.get_transfers(showTop=False, page=2) ``` ### Response #### Success Response (200) - Returns a dictionary containing transfer data. Keys may include information about the transfers listed on the requested page. ``` -------------------------------- ### get_player_stats Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Provides a season-level statistical breakdown for a player within a specific league and season, including metrics like goals, assists, and percentile rankings. ```APIDOC ## get_player_stats ### Description Returns season-level statistical breakdown for a player in a specific league and season, including goals, xG, assists, xA, pass accuracy, and percentile rankings. ### Parameters #### Query Parameters - **player_id** (int) - Required - The unique identifier for the player. - **league_id** (int) - Required - The ID of the league. - **season** (str) - Required - The season identifier (e.g., "2023/2024"). ### Request Example ```python import pandas as pd from fotmob_api import FotmobAPI client = FotmobAPI() player_id = 954 # Mohamed Salah league_id = 47 # Premier League stats = client.get_player_stats(player_id=player_id, league_id=league_id, season="2023/2024") ``` ### Response #### Success Response (200) - **statsSection** (list) - Contains statistical items for the player, including `title`, `statValue`, `per90`, and `percentileRank`. ``` -------------------------------- ### Extract Overall Match Statistics Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/match_stats.ipynb Extracts and normalizes the overall match statistics from the retrieved match details. It also processes the shot map data for further analysis. ```python # overall match stats df_match_stats = pd.json_normalize(match_details["content"]["stats"]["Periods"]["All"]["stats"], record_path=["stats"], meta=["title"], meta_prefix="meta_") df_match_stats[["home_stats", "away_stats"]] = pd.DataFrame(df_match_stats["stats"].tolist(), index=df_match_stats.index) # shots df_match_shots = pd.DataFrame(match_details["content"]["shotmap"]["shots"]) ``` -------------------------------- ### get_match_odds Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Retrieves betting odds for a specific match from available providers. ```APIDOC ## get_match_odds ### Description Returns betting odds for a specific match from available providers. ### Method `get_match_odds` ### Parameters #### Path Parameters - **match_id** (int) - Required - The unique identifier for the match. - **ccode** (str) - Optional - Country code for filtering. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() odds = client.get_match_odds(match_id=4193490, ccode="ENG") ``` ### Response #### Success Response (200) - **odds** (dict) - A dictionary containing betting odds data. ### Response Example ```json { "odds": { "provider1": {"homeWin": 2.5, "draw": 3.2, "awayWin": 2.8} } } ``` ``` -------------------------------- ### Define Column Definitions for Table Plot Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Creates a list of ColumnDefinition objects to configure the appearance and behavior of each column in the league table plot. This includes setting titles, text alignment, width, grouping, and conditional formatting. ```python col_def = ( [ ColumnDefinition( name="idx", title="", textprops={"ha": "left"}, width=0.5, ), ColumnDefinition( name="shortName", title="Team", textprops={"ha": "left", "weight": "bold"}, width=1.5, ), ColumnDefinition( name="played", textprops={"ha": "center"}, width=0.5, group="Basic" ), ColumnDefinition( name="wins", textprops={"ha": "center"}, width=0.5, group="Basic" ), ColumnDefinition( name="draws", textprops={"ha": "center"}, width=0.5, group="Basic" ), ColumnDefinition( name="losses", textprops={"ha": "center"}, width=0.5, group="Basic" ), ColumnDefinition( name="pts", textprops={"ha": "center"}, width=0.5, group="Basic", border="right" ), ColumnDefinition( name="xPoints", textprops={"ha": "center"}, width=0.75, group="Expected Goals" ), ColumnDefinition( name="xg", textprops={"ha": "center"}, width=0.75, group="Expected Goals" ), ColumnDefinition( name="xgConceded", textprops={"ha": "center"}, width=0.75, group="Expected Goals" ), ColumnDefinition( name="xgDiff", textprops={"ha": "center"}, width=0.75, group="Expected Goals" ), ColumnDefinition( name="xPointsDiff", textprops={"ha": "center"}, width=0.75, group="Expected Goals", cmap=normed_cmap(df_table_xg_plot["xPointsDiff"], cmap=matplotlib.cm.coolwarm_r, num_stds=1.5) ) ]) ``` -------------------------------- ### get_player_news Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Fetches the most recent news articles pertaining to a specific player. ```APIDOC ## get_player_news ### Description Returns the latest news articles related to a specific player. ### Parameters #### Query Parameters - **player_id** (int) - Required - The unique identifier for the player. - **language** (str) - Optional - The language for the news articles (e.g., "en-GB"). Defaults to English. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() news = client.get_player_news(player_id=954, language="en-GB") ``` ### Response #### Success Response (200) - Returns a list of news articles, where each article object contains a `title` field. ``` -------------------------------- ### Display Plot Title Source: https://github.com/c-roensholt/fotmob-api/blob/main/examples/league_table.ipynb Renders the title for the plot, which is 'Expected Goals Table - 2023/2024'. ```python Result: Text(0.5, 1.0, 'Expected Goals Table - 2023/2024') ``` -------------------------------- ### get_team_historical_table Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns historical league table finishes and performance data for a specific team across past seasons. ```APIDOC ## get_team_historical_table ### Description Returns historical league table finishes and performance data for a specific team across past seasons. ### Method `get_team_historical_table` ### Parameters #### Path Parameters - **team_id** (int) - Required - The unique identifier for the team. ### Request Example ```python from fotmob_api import FotmobAPI client = FotmobAPI() history = client.get_team_historical_table(team_id=8456) ``` ### Response #### Success Response (200) - **history** (dict) - A dictionary containing historical table data. ### Response Example ```json { "history": { "seasons": [ {"season": "2022/2023", "rank": 1, "teamName": "Manchester City"} ] } } ``` ``` -------------------------------- ### get_league_of_the_week Source: https://context7.com/c-roensholt/fotmob-api/llms.txt Returns the highlighted league of the week for a given country code. ```APIDOC ## get_league_of_the_week Returns the highlighted league of the week for a given country code. ```python client = FotmobAPI() lotw = client.get_league_of_the_week(ccode="ENG") print(lotw) # {'id': 47, 'name': 'Premier League', ...} ``` ```