
Contents
Why opt for Sportmonks’ Football API?
Sportmonks’ API offers a comprehensive set of endpoints covering various aspects of football, including leagues, teams, matches, players, and more. By leveraging these endpoints, developers can access up-to-date information about football leagues worldwide, empowering them to build innovative (mobile) applications and services that cater to the diverse needs of football enthusiasts. Navigate to our complete list of football coverage to explore our amazing football league coverage. Including the Premier League, Champions League and much more.

Why Python?
Python has emerged as one of the popular languages for data gathering, analysis, and automation due to its simplicity, versatility, and robust ecosystem of libraries. With libraries such as requests for making HTTP requests and JSON. Python provides a seamless experience for handling JSON data and interacting with web APIs like Sportmonks’ Football API.
Whether you’re a seasoned developer or just starting your journey in programming, Python’s intuitive syntax and extensive documentation make it accessible to users of all skill levels. By harnessing the power of Python, developers can efficiently integrate Sportmonks’ Football API into their projects, unlocking a world of possibilities for football-related applications.
Sportmonks’ Football API Python
In the following chapters, we’ll guide you through setting up your development environment, making basic API requests, retrieving information about football leagues, fetching match data and incorporating odds data.
Each chapter will feature practical examples and code snippets to illustrate key concepts, helping you better understand using Sportmonks’ API with Python.
By the end of this guide, you’ll have the knowledge and tools to harness Sportmonks’ Football API’s full potential, empowering you to create engaging and innovative football-related applications with Python.
So, let’s embark on this journey and unlock the power of sports data together!
Chapter 1: Setting up your environment
Before using Sportmonks’ Football API with Python, ensuring that your environment is configured correctly is essential. This chapter will guide you through the necessary steps to get started.
1.1 Installing Necessary Python Packages
To begin, make sure you have the necessary Python packages installed. Use the following command to install the requests package:
# Install required packages pip install requests
1.2 Initialising your Python environment
Now, let’s initialize your Python environment by importing the required libraries and defining variables.
# Initialize your Python environment # Import required libraries import requests import json
1.3 Obtaining your API token
To access our API, you’ll need to sign up for an account and obtain an API key. This key is essential for authentication and accessing the data endpoints. Once you have your API key, store it securely for later use. The API key authenticates you as the application developer.
# Define your API key api_key = "YOUR_API_KEY_HERE"
With your environment set up, you’re ready to start making requests to Sportmonks’ Football API!
1.4 Wrapping up
Here’s the code snippet with the environment set up:
# Install required packages pip install requests # Initialize your Python environment # Import required libraries import requests import json # Define your API key api_key = "YOUR_API_KEY_HERE"
Chapter 2: Making basic API requests
In this chapter, we’ll cover the fundamentals of making API requests to Sportmonks’ Football API using Python. We’ll start with basic GET requests to retrieve data from the API endpoints.
2.1 Sending GET Requests
The foundation of interacting with any API is sending HTTP requests. We can easily make GET requests to retrieve data from our Football API endpoints with Python’s requests library.
# Define the API endpoint URL endpoint_url = "API_ENDPOINT_URL_HERE" # Send a GET request to the Sportmonks API endpoint response = requests.get(endpoint_url)
Replace “API_ENDPOINT_URL_HERE” with the specific football endpoint URL provided by our Football API documentation.
2.2 Handling authentication
To make a request to our API, you will need a form of authentication. Luckily, we’ve already defined our API key earlier, and we’ll include it in our requests to authenticate our access to the API.
# Include API key in request headers headers = {"Authorization": api_key} response = requests.get(endpoint_url, headers=headers)
We authenticate our access to Sportmonks’ Football API endpoints by including the API key in the request headers.
2.3 Parsing JSON Responses
Our API returns data in JSON format. We must parse this JSON response in Python to extract the relevant information.
# Check if the request was successful if response.status_code == 200: # Parse JSON response data = response.json() # Process the data further else: print("Failed to retrieve data. Status code:", response.status_code)
By parsing the JSON response, we can access individual data fields and work with them in our Python application.
2.4 Recap
Using the above learned chapters, a basic request in Python looks like this:
# Initialize your Python environment # Import required libraries import requests # Define your API key api_key = "YOUR_API_KEY_HERE" # Define the API endpoint URL base_url = "https://api.sportmonks.com/v3/football" endpoint = ""#define the endpoint URL here include = "" #list your includes here endpoint_url = f"{base_url}{endpoint}?include={include}" # Include API key in request headers headers = {"Authorization": api_key} # Send a GET request to the Sportmonks API endpoint response = requests.get(endpoint_url, headers=headers) # Check if the request was successful if response.status_code == 200: # Parse JSON response data = response.json() else: print("Failed to retrieve data. Status code:", response.status_code)
Now, you have all the essential information to build your football application using Python. Let’s learn more.
Chapter 3: Retrieving leagues information
In this chapter, we’ll explore how to retrieve information about football leagues. We’ll cover how to make requests to the appropriate endpoint and extract the relevant data about different leagues.
3.1 Understanding the structure of league data
Before retrieving league information, it’s essential to understand the structure of the data returned by our Football API. Each league object typically contains details such as the league ID, name, country, and season. Our Football Documentation provides a complete overview of the league’s data response.
3.2 Implementing a function to retrieve All Leagues
We’ll create a function in Python to fetch all available leagues from the Football API. This function will send a GET request to the leagues endpoint and parse the JSON response to extract the list of leagues.
# Initialize your Python environment # Import required libraries import requests # Define your API key api_key = "YOUR_API_KEY_HERE" # Define the API endpoint URL base_url = "https://api.sportmonks.com/v3/football" endpoint = "/leagues" include = "country" endpoint_url = f"{base_url}{endpoint}?include={include}" # Include API key in request headers headers = {"Authorization": api_key} # Send a GET request to the Sportmonks API endpoint response = requests.get(endpoint_url, headers=headers) # Check if the request was successful if response.status_code == 200: # Parse JSON response data = response.json() # Print formatted response data print("List of Football Leagues:") for league in data['data']: print(f"League ID: {league['id']}") print(f"Name: {league['name']}") print(f"Country ID: {league['country_id']}") print(f"Country: {league['country']['name']}") print(f"Short Code: {league['short_code']}") print(f"Image Path: {league['image_path']}") print(f"Type: {league['type']}") print(f"Sub Type: {league['sub_type']}") print(f"Last Played At: {league['last_played_at']}") print(f"Has Jerseys: {league['has_jerseys']}") print() else: print("Failed to retrieve data. Status code:", response.status_code)
{ "data": [ { "id": 2, "sport_id": 1, "country_id": 41, "name": "Champions League", "active": true, "short_code": "UEFA CL", "image_path": "https://cdn.sportmonks.com/images/soccer/leagues/2.png", "type": "league", "sub_type": "cup_international", "last_played_at": "2024-04-17 19:00:00", "category": 1, "has_jerseys": false }, { "id": 5, "sport_id": 1, "country_id": 41, "name": "Europa League", "active": true, "short_code": "UEFA EL", "image_path": "https://cdn.sportmonks.com/images/soccer/leagues/5/5.png", "type": "league", "sub_type": "cup_international", "last_played_at": "2024-04-18 19:00:00", "category": 1, "has_jerseys": false }, // and much more!
We can retrieve and display detailed information about each league by iterating through the list of leagues and accessing their respective fields.
With this chapter, you can effectively retrieve information about football leagues using our Football API in Python.
Chapter 4: Fetching Match Data
This chapter focuses on fetching match data from Sportmonks’ API using Python. We’ll cover how to retrieve information about matches based on different parameters such as league, date, and status.
4.1 Exploring Match Endpoints
The API provides various endpoints for accessing match data, including upcoming matches, finished matches, and matches by specific parameters. We’ll explore these endpoints to understand their functionalities.
4.2 Retrieving Match Information
We’ll implement functions in Python to retrieve fixtures from the 16th till the 17th of April 2024 for the Champions Leagues with player statistics, team information, venue and more.
# Initialize your Python environment # Import required libraries import requests # Define your API key api_key = "YOUR_API_KEY_HERE" # Define the API endpoint URL base_url = "https://api.sportmonks.com/v3/football" endpoint = "/fixtures/between/2024-04-16/2024-04-17" filters = "fixtureLeagues:2" include = "participants;lineups.details;venue;statistics.type" endpoint_url = f"{base_url}{endpoint}?filters={filters}&include={include}" # Include API key in request headers headers = {"Authorization": api_key} # Send a GET request to the Sportmonks API endpoint response = requests.get(endpoint_url, headers=headers) # Check if the request was successful if response.status_code == 200: # Parse JSON response data = response.json() # Print formatted response data print("Fixtures between 2024-04-16 and 2024-04-17:") for fixture in data['data']: print(f"Fixture ID: {fixture['id']}") print(f"Name: {fixture['name']}") print(f"League ID: {fixture['league_id']}") print(f"Starting At: {fixture['starting_at']}") print(f"Result Info: {fixture['result_info']}") print(f"Participants:") for participant in fixture['participants']: print(f" Team Name: {participant['name']}") print(f" Short Code: {participant['short_code']}") print(f" Image Path: {participant['image_path']}") print(f" Last Played At: {participant['last_played_at']}") print(f" Location: {participant['meta']['location']}") print(f" Winner: {participant['meta']['winner']}") print(f" Position: {participant['meta']['position']}") print() print(f"Venue:") venue = fixture['venue'] print(f" Venue ID: {venue['id']}") print(f" Name: {venue['name']}") print(f" City: {venue['city_name']}") print(f" Address: {venue['address']}") print(f" Capacity: {venue['capacity']}") print(f" Surface: {venue['surface']}") print(f" Image Path: {venue['image_path']}") print() print(f"Statistics:") for stat in fixture['statistics']: print(f" Statistic ID: {stat['id']}") print(f" Type: {stat['type']['name']}") print(f" Type ID: {stat['type_id']}") print(f" Team: {stat['location']}") print(f" Value: {stat['data']['value']}") print() print() else: print("Failed to retrieve data. Status code:", response.status_code)
{ "data": [ { "id": 19101802, "sport_id": 1, "league_id": 2, "season_id": 21638, "stage_id": 77463969, "group_id": null, "aggregate_id": 52050, "round_id": null, "state_id": 5, "venue_id": 2166, "name": "Borussia Dortmund vs Atlético Madrid", "starting_at": "2024-04-16 19:00:00", "result_info": "Borussia Dortmund won after full-time.", "leg": "2/2", "details": null, "length": 90, "placeholder": false, "has_odds": true, "starting_at_timestamp": 1713294000, "participants": [ { "id": 68, "sport_id": 1, "country_id": 11, "venue_id": 2166, "gender": "male", "name": "Borussia Dortmund", "short_code": "BVB", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/4/68.png", "founded": 1909, "type": "domestic", "placeholder": false, "last_played_at": "2024-04-21 15:30:00", "meta": { "location": "home", "winner": true, "position": 2 } }, { "id": 7980, "sport_id": 1, "country_id": 32, "venue_id": 140808, "gender": "male", "name": "Atlético Madrid", "short_code": "ATM", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/12/7980.png", "founded": 1903, "type": "domestic", "placeholder": false, "last_played_at": "2024-04-21 16:30:00", "meta": { "location": "away", "winner": false, "position": 1 } } ], "lineups": [ { "id": 9493211895, "sport_id": 1, "fixture_id": 19101802, "player_id": 34084, "team_id": 68, "position_id": 24, "formation_field": null, "type_id": 11, "formation_position": 1, "player_name": "Gregor Kobel", "jersey_number": 1, "details": [ { "id": 1092632472, "fixture_id": 19101802, "player_id": 34084, "team_id": 68, "lineup_id": 9493211895, "type_id": 122, "data": { "value": 10 } }, //and much more
Replace ‘YOUR_API_KEY_HERE’ with your actual Sportmonks API key for authentication. This code sends a GET request to the specified endpoint to retrieve match fixtures between the specified dates for a specific league (in this case, league ID 2). It then parses the JSON response and extracts information about each fixture, including fixture ID, name, start time, result, home team, and away team, and displays this information.
Chapter 5: Incorporating Odds Data
In this chapter, we’ll explore how to incorporate odds data into our football application using the API. We’ll cover how to retrieve odds for upcoming matches, handle the odds data, and integrate it into our Python application.
5.1 Utilising Odds Endpoints
We provide various endpoints for accessing odds data for upcoming matches. We’ll explore these endpoints to understand how to retrieve odds information for different matches.
5.2 Fetching Odds for Upcoming Matches
We’ll implement functions in Python to retrieve odds data for upcoming matches in the UEFA Champions League. These functions will send GET requests to the appropriate odds endpoints and parse the JSON responses to extract the odds information.
# Initialize your Python environment # Import required libraries import requests # Define your API key api_key = "YOUR_API_KEY_HERE" # Define the API endpoint URL base_url = "https://api.sportmonks.com/v3/football" endpoint = "/fixtures/between/2024-04-16/2024-04-17" filters = "fixtureLeagues:2;bookmakers:2;markets:1" include = "participants;odds" endpoint_url = f"{base_url}{endpoint}?filters={filters}&include={include}" # Include API key in request headers headers = {"Authorization": api_key} # Send the request response = requests.get(endpoint_url, headers=headers) # Check if the request was successful if response.status_code == 200: fixtures_data = response.json() # Extract and process fixture information for fixture in fixtures_data['data']: print("Fixture:", fixture['name']) print("Starting at:", fixture['starting_at']) print() print("Participants:") for participant in fixture['participants']: print("- Name:", participant['name']) print(" Location:", participant['meta']['location']) print() print("Odds:") for odd in fixture['odds']: print("- Label:", odd['label']) print(" Value:", odd['value']) print("----------------------------------------------") else: print("Failed to retrieve data. Status code:", response.status_code)
{ "data": [ { "id": 19101802, "sport_id": 1, "league_id": 2, "season_id": 21638, "stage_id": 77463969, "group_id": null, "aggregate_id": 52050, "round_id": null, "state_id": 5, "venue_id": 2166, "name": "Borussia Dortmund vs Atlético Madrid", "starting_at": "2024-04-16 19:00:00", "result_info": "Borussia Dortmund won after full-time.", "leg": "2/2", "details": null, "length": 90, "placeholder": false, "has_odds": true, "starting_at_timestamp": 1713294000, "participants": [ { "id": 68, "sport_id": 1, "country_id": 11, "venue_id": 2166, "gender": "male", "name": "Borussia Dortmund", "short_code": "BVB", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/4/68.png", "founded": 1909, "type": "domestic", "placeholder": false, "last_played_at": "2024-04-21 15:30:00", "meta": { "location": "home", "winner": true, "position": 2 } }, { "id": 7980, "sport_id": 1, "country_id": 32, "venue_id": 140808, "gender": "male", "name": "Atlético Madrid", "short_code": "ATM", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/12/7980.png", "founded": 1903, "type": "domestic", "placeholder": false, "last_played_at": "2024-04-21 16:30:00", "meta": { "location": "away", "winner": false, "position": 1 } } ], "odds": [ { "id": 99109805550, "fixture_id": 19101802, "market_id": 1, "bookmaker_id": 2, "label": "Away", "value": "3.10", "name": null, "sort_order": 2, "market_description": "Full Time Result", "probability": "32.26%", "dp3": "3.100", "fractional": "31/10", "american": "210", "winning": false, "stopped": false, "total": null, "handicap": null, "participants": null, "created_at": "2024-04-10T23:21:27.000000Z", "original_label": "2", "latest_bookmaker_update": "2024-04-16 18:50:04" }, { "id": 99109805547, "fixture_id": 19101802, "market_id": 1, "bookmaker_id": 2, "label": "Draw", "value": "3.50", "name": null, "sort_order": 1, "market_description": "Full Time Result", "probability": "28.57%", "dp3": "3.500", "fractional": "7/2", "american": "250", "winning": false, "stopped": false, "total": null, "handicap": null, "participants": null, "created_at": "2024-04-10T23:21:27.000000Z", "original_label": "Draw", "latest_bookmaker_update": "2024-04-16 18:50:04" }, { "id": 99109805544, "fixture_id": 19101802, "market_id": 1, "bookmaker_id": 2, "label": "Home", "value": "2.15", "name": null, "sort_order": 0, "market_description": "Full Time Result", "probability": "46.51%", "dp3": "2.150", "fractional": "43/20", "american": "114", "winning": true, "stopped": false, "total": null, "handicap": null, "participants": null, "created_at": "2024-04-10T23:21:27.000000Z", "original_label": "1", "latest_bookmaker_update": "2024-04-16 18:50:04" } ] }, { "id": 19101806, "sport_id": 1, "league_id": 2, "season_id": 21638, "stage_id": 77463969, "group_id": null, "aggregate_id": 52052, "round_id": null, "state_id": 5, "venue_id": 300228, "name": "FC Barcelona vs Paris Saint Germain", "starting_at": "2024-04-16 19:00:00", "result_info": "Paris Saint Germain won after full-time.", "leg": "2/2", "details": null, "length": 90, "placeholder": false, "has_odds": true, "starting_at_timestamp": 1713294000, "participants": [ { "id": 591, "sport_id": 1, "country_id": 17, "venue_id": 131, "gender": "male", "name": "Paris Saint Germain", "short_code": "PSG", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/15/591.png", "founded": 1970, "type": "domestic", "placeholder": false, "last_played_at": "2024-04-24 17:00:00", "meta": { "location": "away", "winner": true, "position": 2 } }, { "id": 83, "sport_id": 1, "country_id": 32, "venue_id": 300228, "gender": "male", "name": "FC Barcelona", "short_code": "BAR", "image_path": "https://cdn.sportmonks.com/images/soccer/teams/19/83.png", "founded": 1899, "type": "domestic", "placeholder": false, "last_played_at": "2024-04-21 19:00:00", "meta": { "location": "home", "winner": false, "position": 1 } } ], "odds": [ { "id": 99109805305, "fixture_id": 19101806, "market_id": 1, "bookmaker_id": 2, "label": "Away", "value": "3.00", "name": null, "sort_order": 2, "market_description": "Full Time Result", "probability": "33.33%", "dp3": "3.000", "fractional": "3", "american": "200", "winning": true, "stopped": false, "total": null, "handicap": null, "participants": null, "created_at": "2024-04-10T23:21:27.000000Z", "original_label": "2", "latest_bookmaker_update": "2024-04-16 18:50:06" }, { "id": 99109805294, "fixture_id": 19101806, "market_id": 1, "bookmaker_id": 2, "label": "Draw", "value": "4.00", "name": null, "sort_order": 1, "market_description": "Full Time Result", "probability": "25%", "dp3": "4.000", "fractional": "4", "american": "300", "winning": false, "stopped": false, "total": null, "handicap": null, "participants": null, "created_at": "2024-04-10T23:21:27.000000Z", "original_label": "Draw", "latest_bookmaker_update": "2024-04-16 18:50:06" }, { "id": 99109805292, "fixture_id": 19101806, "market_id": 1, "bookmaker_id": 2, "label": "Home", "value": "2.15", "name": null, "sort_order": 0, "market_description": "Full Time Result", "probability": "46.51%", "dp3": "2.150", "fractional": "43/20", "american": "114", "winning": false, "stopped": false, "total": null, "handicap": null, "participants": null, "created_at": "2024-04-10T23:21:27.000000Z", "original_label": "1", "latest_bookmaker_update": "2024-04-16 18:50:06" } ] },
This script performs the following steps:
– Constructs the request URL with the specified filters and includes.
– Sends the HTTP GET request to the Sportmonks API.
– Checks if the request was successful (status code 200).
– Parses the JSON response data.
– Extracts and prints fixture information, including participants and odds.
– You need to replace “your_api_key_here” with your actual Sportmonks API key to authenticate the request. This script prints fixture details, participant information (including their location), and odds for each fixture retrieved from the API response.
Conclusion: Unlocking the Power of Sportmonks’ Football API with Python
Throughout this guide, we’ve embarked on a journey to harness the full potential of Sportmonks’ Football API using the versatile programming language Python. We’ve explored the API’s vast capabilities, from retrieving basic information about football leagues to fetching detailed match data and incorporating odds information into our applications.
By opting for Sportmonks’ Football API, developers gain access to a comprehensive set of endpoints covering various aspects of football, including leagues, teams, matches, players, and odds. This wealth of data empowers developers to build innovative applications and services tailored to the diverse needs of football enthusiasts worldwide.
Thanks to its simplicity, readability, and extensive library support, Python emerged as the language of choice for integrating with Sportmonks’ API. With libraries such as requests for making HTTP requests and JSON for handling JSON data, Python provides a seamless experience for interacting with web APIs like Sportmonks’.
This guide covers essential topics such as setting up your development environment, making basic API requests, retrieving league and match data, and incorporating odds information into your applications. Each chapter featured practical examples and code snippets to illustrate key concepts, ensuring a deeper understanding of using Sportmonks’ API with Python.
As you’ve learned, Python’s intuitive syntax and extensive documentation make it accessible to users of all skill levels, whether you’re a seasoned developer or just starting your programming journey. By harnessing the power of Python and Sportmonks’ Football API, you’re equipped to create engaging and innovative football-related applications that delight users and provide valuable insights into the world of football.
So, as you continue leveraging sports data to create impactful applications, remember the possibilities are endless with Sportmonks’ Football API and Python by your side. Let’s continue to unlock the power of sports data together!