Football League Table using an API

In many modern programs and websites, data does not come from a file stored on your computer. Instead, it is often retrieved live from the internet. One of the most common ways this happens is through an API. In this challenge, we will learn how to use an online API to retrieve real football data and process it in a Python program.

What is an API?

API stands for Application Programming Interface.

In simple terms, an API is a way for one program to talk to another program. It allows software developers to request data or services from an external system in a controlled and predictable way.

For example:

  • A weather app uses an API to request today’s forecast
  • A travel website uses an API to retrieve flight prices
  • An e-commerce website (online shop) may use an API to retrieve up-to-date currency exchange rate
  • A football website uses an API to display league tables and player information

Instead of manually copying information from a website, a program can send a request to an API and receive the data automatically. This is extremely relevant especially when your program needs to access up-to-date data from an external source/supplier such as currency exchange rates, weather forecast data etc.

The Sports DB API

For this lesson, we will be using TheSportsDB API, which provides free access to a wide range of sports data, including:

  • English Premier League tables
  • Football teams and players
  • Stadiums (venues)
  • Match results and fixtures

You can explore everything the API offers by reading the official documentation here:
https://www.thesportsdb.com/documentation

Note that for the purpose of this task, we will be using the free API (using API key “123”) which only gives you restricted access to some of the sports data.

Understanding how to read API documentation is an important skill for any programmer. The documentation explains:

  • What data is available
  • What type of requests you can make
  • Which parameters you need to include in your request

Making an API Request with a URL

To access data from an API, you usually send a request using a URL.

This URL often contains a query string, which is the part of the URL that includes extra information (parameters) used to filter the data.

For example, an API URL might include:

  • The name of a league
  • The name of a player
  • A team ID or season year

These parameters tell the API exactly what data you want.
The available parameters and how to use them are explained in the API documentation.

When writing your Python program, you will:

  1. Send a request to the API using a URL
  2. Receive data back from the API
  3. Process (parse) that data so your program can use it

What is JSON?

When an API sends data back to your program, it usually uses a format called JSON.

JSON stands for JavaScript Object Notation, but it is widely used in many programming languages, including Python.

JSON is a structured data format that stores information using:

  • Key–value pairs
  • Lists (arrays)
  • Nested objects

A simplified example of JSON data may replicate the following structure:

  • A league has a name
  • A league contains teams
  • Each team has players
  • Each player has a name and position

This structure makes JSON easy for both humans and computers to read.

What Does “Parsing JSON” Mean?

When we say parsing JSON, we mean: Converting JSON data into a format that our program can understand and work with.

In Python, this usually means:

  • Turning JSON data into dictionaries and lists
  • Accessing values using keys
  • Looping through lists of data
  • Extracting only the information we need

For example, instead of displaying all the data returned by the API, you might:

  • Extract team names only
  • Find a specific player
  • Display league positions in a table format

Parsing allows you to transform raw data into useful information.

The Challenge

Your task is to explore TheSportsDB API and write a Python program that retrieves and processes live football data.

You should begin by carefully reading the API documentation to understand which requests are available and which parameters you need to use.

Task Ideas
Your program should complete tasks such as:

    Allowing the user to enter the name of a football player and displaying the team they currently play for
    Displaying an up-to-date English Premier League table
    Allowing the user to enter the name of a venue and displaying the description of this venue and its capacity (number of spectators)

You will need to:

    Choose the correct API endpoint
    Build the request URL using the correct parameters
    Retrieve the JSON data
    Parse the JSON to extract the required information
    Display the results clearly to the user

⚠️ Important: You do not need to hard-code any football data into your program. All information should come directly from the API.

Python Code: Player Search

Here is an example of Python code to search for a player based on their name and return the search results: Full name of the players matching the search criteria and the club they play for.

Python Code: League Table

Here is an example of Python code to display an extract of the English Football Premiere League table for the current season!

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: