Quick Start Tutorial for the footballdataorg package

You can install the package easily using

pip install footballdataorg

Import package


In [1]:
from footballdataorg.fd import FD
import json

Create FD object


In [2]:
fd = FD()

Get Premier League competition object

You can find the league codes here.


In [3]:
pl = fd.get_competition(league_code='PL')

In [4]:
print(json.dumps(pl, indent=2))


{
  "_links": {
    "self": {
      "href": "http://api.football-data.org/v1/competitions/445"
    },
    "teams": {
      "href": "http://api.football-data.org/v1/competitions/445/teams"
    },
    "fixtures": {
      "href": "http://api.football-data.org/v1/competitions/445/fixtures"
    },
    "leagueTable": {
      "href": "http://api.football-data.org/v1/competitions/445/leagueTable"
    }
  },
  "id": 445,
  "caption": "Premier League 2017/18",
  "league": "PL",
  "year": "2017",
  "currentMatchday": 5,
  "numberOfMatchdays": 38,
  "numberOfTeams": 20,
  "numberOfGames": 380,
  "lastUpdated": "2017-09-17T17:00:25Z"
}

Get the teams of the competition

Just pass the competition object to the method


In [5]:
teams = fd.get_teams(competition=pl)

Search teams by name


In [6]:
teams = fd.search_teams('madrid')

In [7]:
print(json.dumps(teams, indent=2))


{
  "_links": {
    "self": {
      "href": "http://api.football-data.org/v1/teams?name=madrid"
    }
  },
  "searchQuery": "madrid",
  "count": 5,
  "teams": [
    {
      "id": 78,
      "name": "Club Atl\u00e9tico de Madrid",
      "currentCompetition": 455,
      "currentLeague": "PD"
    },
    {
      "id": 86,
      "name": "Real Madrid CF",
      "currentCompetition": 455,
      "currentLeague": "PD"
    },
    {
      "id": 87,
      "name": "Rayo Vallecano de Madrid",
      "currentCompetition": 437,
      "currentLeague": "SD"
    },
    {
      "id": 281,
      "name": "Ath Madrid B",
      "currentCompetition": null,
      "currentLeague": null
    },
    {
      "id": 289,
      "name": "Real Madrid Castilla",
      "currentCompetition": null,
      "currentLeague": null
    }
  ]
}

Get a single team


In [8]:
manchester_united = fd.get_team('66')

In [9]:
print(json.dumps(manchester_united, indent=2))


{
  "_links": {
    "self": {
      "href": "http://api.football-data.org/v1/teams/66"
    },
    "fixtures": {
      "href": "http://api.football-data.org/v1/teams/66/fixtures"
    },
    "players": {
      "href": "http://api.football-data.org/v1/teams/66/players"
    }
  },
  "name": "Manchester United FC",
  "code": "MUFC",
  "shortName": "ManU",
  "squadMarketValue": null,
  "crestUrl": "http://upload.wikimedia.org/wikipedia/de/d/da/Manchester_United_FC.svg"
}

Get fixtures in the upcoming two weeks


In [10]:
fixtures = fd.get_fixtures(competition=pl, team=manchester_united, timeFrame='n14')['fixtures']

In [11]:
print(json.dumps(fixtures, indent=2))


[
  {
    "_links": {
      "self": {
        "href": "http://api.football-data.org/v1/fixtures/159272"
      },
      "competition": {
        "href": "http://api.football-data.org/v1/competitions/445"
      },
      "homeTeam": {
        "href": "http://api.football-data.org/v1/teams/340"
      },
      "awayTeam": {
        "href": "http://api.football-data.org/v1/teams/66"
      }
    },
    "date": "2017-09-23T14:00:00Z",
    "status": "TIMED",
    "matchday": 6,
    "homeTeamName": "Southampton FC",
    "awayTeamName": "Manchester United FC",
    "result": {
      "goalsHomeTeam": null,
      "goalsAwayTeam": null
    },
    "odds": null
  },
  {
    "_links": {
      "self": {
        "href": "http://api.football-data.org/v1/fixtures/159261"
      },
      "competition": {
        "href": "http://api.football-data.org/v1/competitions/445"
      },
      "homeTeam": {
        "href": "http://api.football-data.org/v1/teams/66"
      },
      "awayTeam": {
        "href": "http://api.football-data.org/v1/teams/354"
      }
    },
    "date": "2017-09-30T14:00:00Z",
    "status": "TIMED",
    "matchday": 7,
    "homeTeamName": "Manchester United FC",
    "awayTeamName": "Crystal Palace FC",
    "result": {
      "goalsHomeTeam": null,
      "goalsAwayTeam": null
    },
    "odds": null
  }
]

Get head to head information about an upcoming fixture


In [12]:
head2head = fd.get_fixture('159293', head2head=5)

In [13]:
print(json.dumps(head2head, indent=2))


{
  "fixture": {
    "_links": {
      "self": {
        "href": "http://api.football-data.org/v1/fixtures/159293"
      },
      "competition": {
        "href": "http://api.football-data.org/v1/competitions/445"
      },
      "homeTeam": {
        "href": "http://api.football-data.org/v1/teams/70"
      },
      "awayTeam": {
        "href": "http://api.football-data.org/v1/teams/66"
      }
    },
    "date": "2017-09-09T16:30:00Z",
    "status": "FINISHED",
    "matchday": 4,
    "homeTeamName": "Stoke City FC",
    "awayTeamName": "Manchester United FC",
    "result": {
      "goalsHomeTeam": 2,
      "goalsAwayTeam": 2,
      "halfTime": {
        "goalsHomeTeam": 1,
        "goalsAwayTeam": 1
      }
    },
    "odds": null
  },
  "head2head": {
    "count": 5,
    "timeFrameStart": "2015-12-26",
    "timeFrameEnd": "2017-09-09",
    "homeTeamWins": 1,
    "awayTeamWins": 1,
    "draws": 3,
    "lastHomeWinHomeTeam": {
      "_links": {
        "self": {
          "href": "http://api.football-data.org/v1/fixtures/146924"
        },
        "competition": {
          "href": "http://api.football-data.org/v1/competitions/398"
        },
        "homeTeam": {
          "href": "http://api.football-data.org/v1/teams/70"
        },
        "awayTeam": {
          "href": "http://api.football-data.org/v1/teams/66"
        }
      },
      "date": "2015-12-26T12:45:00Z",
      "status": "FINISHED",
      "matchday": 18,
      "homeTeamName": "Stoke City FC",
      "awayTeamName": "Manchester United FC",
      "result": {
        "goalsHomeTeam": 2,
        "goalsAwayTeam": 0,
        "halfTime": {
          "goalsHomeTeam": 2,
          "goalsAwayTeam": 0
        }
      },
      "odds": null
    },
    "lastWinHomeTeam": {
      "_links": {
        "self": {
          "href": "http://api.football-data.org/v1/fixtures/146924"
        },
        "competition": {
          "href": "http://api.football-data.org/v1/competitions/398"
        },
        "homeTeam": {
          "href": "http://api.football-data.org/v1/teams/70"
        },
        "awayTeam": {
          "href": "http://api.football-data.org/v1/teams/66"
        }
      },
      "date": "2015-12-26T12:45:00Z",
      "status": "FINISHED",
      "matchday": 18,
      "homeTeamName": "Stoke City FC",
      "awayTeamName": "Manchester United FC",
      "result": {
        "goalsHomeTeam": 2,
        "goalsAwayTeam": 0,
        "halfTime": {
          "goalsHomeTeam": 2,
          "goalsAwayTeam": 0
        }
      },
      "odds": null
    },
    "lastAwayWinAwayTeam": null,
    "lastWinAwayTeam": {
      "_links": {
        "self": {
          "href": "http://api.football-data.org/v1/fixtures/146865"
        },
        "competition": {
          "href": "http://api.football-data.org/v1/competitions/398"
        },
        "homeTeam": {
          "href": "http://api.football-data.org/v1/teams/66"
        },
        "awayTeam": {
          "href": "http://api.football-data.org/v1/teams/70"
        }
      },
      "date": "2016-02-02T20:00:00Z",
      "status": "FINISHED",
      "matchday": 24,
      "homeTeamName": "Manchester United FC",
      "awayTeamName": "Stoke City FC",
      "result": {
        "goalsHomeTeam": 3,
        "goalsAwayTeam": 0
      },
      "odds": null
    },
    "fixtures": [
      {
        "_links": {
          "self": {
            "href": "http://api.football-data.org/v1/fixtures/159293"
          },
          "competition": {
            "href": "http://api.football-data.org/v1/competitions/445"
          },
          "homeTeam": {
            "href": "http://api.football-data.org/v1/teams/70"
          },
          "awayTeam": {
            "href": "http://api.football-data.org/v1/teams/66"
          }
        },
        "date": "2017-09-09T16:30:00Z",
        "status": "FINISHED",
        "matchday": 4,
        "homeTeamName": "Stoke City FC",
        "awayTeamName": "Manchester United FC",
        "result": {
          "goalsHomeTeam": 2,
          "goalsAwayTeam": 2,
          "halfTime": {
            "goalsHomeTeam": 1,
            "goalsAwayTeam": 1
          }
        },
        "odds": null
      },
      {
        "_links": {
          "self": {
            "href": "http://api.football-data.org/v1/fixtures/150633"
          },
          "competition": {
            "href": "http://api.football-data.org/v1/competitions/426"
          },
          "homeTeam": {
            "href": "http://api.football-data.org/v1/teams/70"
          },
          "awayTeam": {
            "href": "http://api.football-data.org/v1/teams/66"
          }
        },
        "date": "2017-01-21T15:00:00Z",
        "status": "FINISHED",
        "matchday": 22,
        "homeTeamName": "Stoke City FC",
        "awayTeamName": "Manchester United FC",
        "result": {
          "goalsHomeTeam": 1,
          "goalsAwayTeam": 1,
          "halfTime": {
            "goalsHomeTeam": 1,
            "goalsAwayTeam": 0
          }
        },
        "odds": {
          "homeWin": 5.5,
          "draw": 4.0,
          "awayWin": 1.65
        }
      },
      {
        "_links": {
          "self": {
            "href": "http://api.football-data.org/v1/fixtures/150779"
          },
          "competition": {
            "href": "http://api.football-data.org/v1/competitions/426"
          },
          "homeTeam": {
            "href": "http://api.football-data.org/v1/teams/66"
          },
          "awayTeam": {
            "href": "http://api.football-data.org/v1/teams/70"
          }
        },
        "date": "2016-10-02T11:00:00Z",
        "status": "FINISHED",
        "matchday": 7,
        "homeTeamName": "Manchester United FC",
        "awayTeamName": "Stoke City FC",
        "result": {
          "goalsHomeTeam": 1,
          "goalsAwayTeam": 1,
          "halfTime": {
            "goalsHomeTeam": 0,
            "goalsAwayTeam": 0
          }
        },
        "odds": {
          "homeWin": 1.3,
          "draw": 5.0,
          "awayWin": 12.0
        }
      },
      {
        "_links": {
          "self": {
            "href": "http://api.football-data.org/v1/fixtures/146865"
          },
          "competition": {
            "href": "http://api.football-data.org/v1/competitions/398"
          },
          "homeTeam": {
            "href": "http://api.football-data.org/v1/teams/66"
          },
          "awayTeam": {
            "href": "http://api.football-data.org/v1/teams/70"
          }
        },
        "date": "2016-02-02T20:00:00Z",
        "status": "FINISHED",
        "matchday": 24,
        "homeTeamName": "Manchester United FC",
        "awayTeamName": "Stoke City FC",
        "result": {
          "goalsHomeTeam": 3,
          "goalsAwayTeam": 0
        },
        "odds": null
      },
      {
        "_links": {
          "self": {
            "href": "http://api.football-data.org/v1/fixtures/146924"
          },
          "competition": {
            "href": "http://api.football-data.org/v1/competitions/398"
          },
          "homeTeam": {
            "href": "http://api.football-data.org/v1/teams/70"
          },
          "awayTeam": {
            "href": "http://api.football-data.org/v1/teams/66"
          }
        },
        "date": "2015-12-26T12:45:00Z",
        "status": "FINISHED",
        "matchday": 18,
        "homeTeamName": "Stoke City FC",
        "awayTeamName": "Manchester United FC",
        "result": {
          "goalsHomeTeam": 2,
          "goalsAwayTeam": 0,
          "halfTime": {
            "goalsHomeTeam": 2,
            "goalsAwayTeam": 0
          }
        },
        "odds": null
      }
    ]
  }
}

Get the players of a team


In [14]:
players = fd.get_players(manchester_united)

In [15]:
print(json.dumps(players, indent=2))


{
  "_links": {
    "self": {
      "href": "http://api.football-data.org/v1/teams/66/players"
    },
    "team": {
      "href": "http://api.football-data.org/v1/teams/66"
    }
  },
  "count": 25,
  "players": [
    {
      "name": "Romelu Lukaku",
      "position": "Centre-Forward",
      "jerseyNumber": 9,
      "dateOfBirth": "1993-05-13",
      "nationality": "Belgium",
      "contractUntil": "2022-06-30",
      "marketValue": null
    },
    {
      "name": "David de Gea",
      "position": "Keeper",
      "jerseyNumber": 1,
      "dateOfBirth": "1990-11-07",
      "nationality": "Spain",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Sergio Romero",
      "position": "Keeper",
      "jerseyNumber": 20,
      "dateOfBirth": "1987-02-22",
      "nationality": "Argentina",
      "contractUntil": "2021-06-30",
      "marketValue": null
    },
    {
      "name": "Eric Bailly",
      "position": "Centre-Back",
      "jerseyNumber": 3,
      "dateOfBirth": "1994-04-12",
      "nationality": "Cote d'Ivoire",
      "contractUntil": "2020-06-30",
      "marketValue": null
    },
    {
      "name": "Chris Smalling",
      "position": "Centre-Back",
      "jerseyNumber": 12,
      "dateOfBirth": "1989-11-22",
      "nationality": "England",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Marcos Rojo",
      "position": "Centre-Back",
      "jerseyNumber": 5,
      "dateOfBirth": "1990-03-20",
      "nationality": "Argentina",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Phil Jones",
      "position": "Centre-Back",
      "jerseyNumber": 4,
      "dateOfBirth": "1992-02-21",
      "nationality": "England",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Daley Blind",
      "position": "Left-Back",
      "jerseyNumber": 17,
      "dateOfBirth": "1990-03-09",
      "nationality": "Netherlands",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Luke Shaw",
      "position": "Left-Back",
      "jerseyNumber": 23,
      "dateOfBirth": "1995-07-12",
      "nationality": "England",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Matteo Darmian",
      "position": "Right-Back",
      "jerseyNumber": 36,
      "dateOfBirth": "1989-12-02",
      "nationality": "Italy",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Antonio Valencia",
      "position": "Right-Back",
      "jerseyNumber": 25,
      "dateOfBirth": "1985-08-04",
      "nationality": "Ecuador",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Michael Carrick",
      "position": "Defensive Midfield",
      "jerseyNumber": 16,
      "dateOfBirth": "1981-07-28",
      "nationality": "England",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Paul Pogba",
      "position": "Central Midfield",
      "jerseyNumber": 6,
      "dateOfBirth": "1993-03-15",
      "nationality": "France",
      "contractUntil": "2021-06-30",
      "marketValue": null
    },
    {
      "name": "Ander Herrera",
      "position": "Central Midfield",
      "jerseyNumber": 21,
      "dateOfBirth": "1989-08-14",
      "nationality": "Spain",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Marouane Fellaini",
      "position": "Central Midfield",
      "jerseyNumber": 27,
      "dateOfBirth": "1987-11-22",
      "nationality": "Belgium",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Ashley Young",
      "position": "Left Midfield",
      "jerseyNumber": 18,
      "dateOfBirth": "1985-07-09",
      "nationality": "England",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Henrikh Mkhitaryan",
      "position": "Attacking Midfield",
      "jerseyNumber": 22,
      "dateOfBirth": "1989-01-21",
      "nationality": "Armenia",
      "contractUntil": "2020-06-30",
      "marketValue": null
    },
    {
      "name": "Juan Mata",
      "position": "Attacking Midfield",
      "jerseyNumber": 8,
      "dateOfBirth": "1988-04-28",
      "nationality": "Spain",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Jesse Lingard",
      "position": "Left Wing",
      "jerseyNumber": 14,
      "dateOfBirth": "1992-12-15",
      "nationality": "England",
      "contractUntil": "2021-06-30",
      "marketValue": null
    },
    {
      "name": "Anthony Martial",
      "position": "Centre-Forward",
      "jerseyNumber": 11,
      "dateOfBirth": "1995-12-05",
      "nationality": "France",
      "contractUntil": "2019-06-30",
      "marketValue": null
    },
    {
      "name": "Zlatan Ibrahimovic",
      "position": "Centre-Forward",
      "jerseyNumber": 10,
      "dateOfBirth": "1981-10-03",
      "nationality": "Sweden",
      "contractUntil": "2018-06-30",
      "marketValue": null
    },
    {
      "name": "Marcus Rashford",
      "position": "Centre-Forward",
      "jerseyNumber": 19,
      "dateOfBirth": "1997-10-31",
      "nationality": "England",
      "contractUntil": "2020-06-30",
      "marketValue": null
    },
    {
      "name": "Nemanja Matic",
      "position": "Defensive Midfield",
      "jerseyNumber": 31,
      "dateOfBirth": "1988-08-01",
      "nationality": "Serbia",
      "contractUntil": "2020-06-30",
      "marketValue": null
    },
    {
      "name": "Victor Lindel\u00f6f",
      "position": "Centre-Back",
      "jerseyNumber": 2,
      "dateOfBirth": "1994-07-17",
      "nationality": "Sweden",
      "contractUntil": "2021-06-30",
      "marketValue": null
    },
    {
      "name": "Joel Pereira",
      "position": "Keeper",
      "jerseyNumber": 40,
      "dateOfBirth": "1996-06-28",
      "nationality": "Portugal",
      "contractUntil": "2021-06-30",
      "marketValue": null
    }
  ]
}