SoFIFA

class soccerdata.SoFIFA(leagues=None, versions='latest', proxy=None, no_cache=False, no_store=False, data_dir=PosixPath('/home/docs/soccerdata/data/SoFIFA'))

Provides pd.DataFrames from data at http://sofifa.com.

Data will be downloaded as necessary and cached locally in ~/soccerdata/data/SoFIFA.

Parameters:
  • leagues (string or iterable, optional) – IDs of leagues to include.

  • versions (string, int or list of int, optional) – FIFA releases to include. Should be specified by their ID used in the URL (e.g., 230034). Alternatively, the string “all” can be used to include all versions and “latest” to include the latest version only. Defaults to “latest”.

  • proxy ('tor' or dict or list(dict) or callable, optional) –

    Use a proxy to hide your IP address. Valid options are:
    • ”tor”: Uses the Tor network. Tor should be running in the background on port 9050.

    • dict: A dictionary with the proxy to use. The dict should be a mapping of supported protocols to proxy addresses. For example:

      {
          'http': 'http://10.10.1.10:3128',
          'https': 'http://10.10.1.10:1080',
      }
      
    • list(dict): A list of proxies to choose from. A different proxy will be selected from this list after failed requests, allowing rotating proxies.

    • callable: A function that returns a valid proxy. This function will be called after failed requests, allowing rotating proxies.

  • no_cache (bool) – If True, will not use cached data.

  • no_store (bool) – If True, will not store downloaded data.

  • data_dir (Path) – Path to directory where data will be cached.

read_leagues()

Retrieve selected leagues from the datasource.

Return type:

pd.DataFrame

read_versions(max_age=1)

Retrieve available FIFA releases and rating updates.

Parameters:

max_age (int for age in days, or timedelta object) – The max. age of the locally cached release history before a new version is downloaded.

Raises:

TypeError – If max_age is not an integer or timedelta object.

Return type:

pd.DataFrame

read_teams()

Retrieve all teams for the selected leagues.

Return type:

pd.DataFrame

read_players(team=None)

Retrieve all players for the selected leagues.

Parameters:

team (str or list of str, optional) – Team(s) to retrieve. If None, will retrieve all teams.

Raises:

ValueError – If no data is found for the given team(s) in the selected leagues.

Return type:

pd.DataFrame

classmethod available_leagues()

Return a list of league IDs available for this source.

Return type:

List[str]

read_team_ratings()

Retrieve ratings for all teams in the selected leagues.

Return type:

pd.DataFrame

read_player_ratings(team=None, player=None)

Retrieve ratings for players.

Parameters:
  • team (str or list of str, optional) – Team(s) to retrieve. If None, will retrieve all teams.

  • player (int or list of int, optional) – Player(s) to retrieve. If None, will retrieve all players.

Return type:

pd.DataFrame