Skip to content
Pixel
العربية

5-3Unit 5 · Data Collection and Cleaning

Open Data and APIs

10 min readStart exercises
In this lesson
  1. The Big Idea
  2. What Is Open Data?
  3. Main Sources of Open Data
  4. Getting Data Through APIs
  5. Using Data and Citing the Source
  6. Try It Yourself
  7. Common Mistakes
  8. Key Points
  9. FAQ

The Big Idea

You do not always have to collect data yourself; many organisations publish useful data under terms that allow it to be reused. This is open data. You can download it in a browser, or your program can request it directly through an API (Application Programming Interface): the program sends a request to an endpoint, and the server replies with a response carrying the data, often in JSON format. But "open" does not mean "no rules": every dataset has terms of use to respect and a source to cite.

What Is Open Data?

Open data is data available for anyone to use under a clear licence or terms that allow access, reuse and redistribution. The Arabic edition stresses an important point: being public or free does not, on its own, make data open. A chart on a website, or a table you can view for free, is not necessarily something you are allowed to republish. What makes data open is a licence that explicitly allows it.

Who publishes open data? Government bodies, organisations, researchers and companies. But licences, quality and definitions vary from one dataset to another, even on the same website.

Four things to check before you use it

  1. Source and quality: who published it? When was it last updated? How was it collected?
  2. Access method: is it a direct download, an API, or other tools the source provides?
  3. Licence or terms of use: what are you allowed to do with it?
  4. Fit to the analysis question: are its definitions, years and categories what you actually need?

These steps support responsible use, but on their own they do not guarantee a good result; the quality of the result also depends on the quality of the data itself and the method you analyse it with.

Four checks before using open data Four cards. First, source and quality: who published the data, when it was updated and how it was collected. Second, access method: a direct download in a browser, an API, or tools the source provides. Third, licence and terms of use: what is allowed in terms of use, reuse, redistribution and publishing. Fourth, fit to your question: definitions, years and countries, and whether it holds what you need. A warning at the bottom: free or public is not automatically open; openness needs a licence that allows reuse. Before you use an open dataset: four checks 1) Source and quality Who published it? When updated? How was it collected? 2) Access method Direct download in a browser or an API, or the source's tools 3) Licence / terms of use What is allowed: use, reuse, redistribution, publishing? 4) Fit to your question Definitions, years, countries Does it hold what you need? Free or public is not automatically open: openness needs a licence allowing reuse
Before building an analysis on a dataset, check it from these four angles.

Main Sources of Open Data

The book gives three examples of portals and platforms with useful data, reminding you that each dataset's terms still need checking, even from a well-known source:

| Provider | What does it offer? | Useful for | |---|---|---| | World Bank Open Data | Statistics on the economy, population, education and health for countries around the world | International comparisons, provided the definitions and time periods suit your question | | UN Data | International statistics published by the United Nations and its agencies | A range of international topics, after checking each indicator's source and definition | | Kaggle | A platform for data analysis competitions, where datasets in many fields are available to the public | Getting data to study and research machine learning, after evaluating each dataset's source and licence |

Notice how Kaggle is different: its datasets are uploaded by many different users and organisations, so the book insists on evaluating each dataset's source and licence separately.

Access methods also differ: a direct download of a file in the browser, an API, or other tools the source itself provides.

Getting Data Through APIs

An API (Application Programming Interface) is a set of rules that lets one program request data or functions from another program or service. Instead of opening a website, searching and clicking "download" yourself, your program can send the request directly to the API. This helps when you need to repeat requests (say, every day) and process the results automatically, within the limits the service sets.

The request–response sequence

  1. Request: the client, meaning your program, sends a request to an endpoint, a specific address or path in the API that accepts a certain kind of request.
  2. Response: the server processes the request and sends back a response that may contain data or an error message, in a format the service defines.
  3. Use: the program reads the response, then uses the data for analysis or an app, or handles the error, depending on what came back.
Request and response with an API On one side is the client, your program or app; on the other is the server, the service holding the data. Step 1: a request arrow from the client to an endpoint on the server, labelled https://api.example.org/weather?city=Aswan. Step 2: a response arrow from the server back to the client, carrying data or an error message in a format set by the service, such as JSON, for example {"city": "Aswan", "temp_c": 31}. Step 3: the program reads the response and either uses the data for analysis or handles the error. At the bottom: API access does not cancel the terms of use or the request limits. Getting data through an API Client your program or app code Server the service with the data 1) Request to an endpoint https://api.example.org/weather?city=Aswan 2) Response: data or an error {"city": "Aswan", "temp_c": 31} in a format set by the service, e.g. JSON 3) The program reads the response: uses the data, or handles the error API access does not cancel the terms of use or the request limits
An illustrative example with a made-up address (example.org): the request goes to the endpoint, and the response comes back with data or an error.

Example: a weather app

The weather app on your phone does not measure temperature itself; it sends a request to a weather service. Imagine the endpoint of an example service is:

https://api.example.org/weather?city=Aswan

The server replies with a response like:

json
{
  "city": "Aswan",
  "date": "2026-11-27",
  "temp_c": 31,
  "condition": "sunny"
}

The app reads the value linked to temp_c and shows it to you. If it asks for a city that does not exist, an error message may come back instead of data, such as:

json
{
  "error": "city not found"
}

Then the program has to handle the error, for example by showing the user a clear message instead of crashing or displaying an empty number.

What is JSON?

JSON (JavaScript Object Notation) is a common text format for representing structured data using objects (name–value pairs inside curly braces), arrays (lists inside square brackets) and various values such as text and numbers. Many languages and tools support it, but it is not the only format an API may use; the service decides the format.

Using Data and Citing the Source

Terms of use

Open data comes with a licence or terms that set out what is allowed when accessing, reusing and redistributing it. So read that dataset's own terms before using it: one dataset may allow republishing in a public report, while another sets different conditions.

Citing the source

Use the data according to the licence and attribute it to its source in the required way. An attribution or citation may include:

  • The publisher.
  • The dataset name.
  • The version, update date or access date.
  • The link to the source.

All of this follows the provider's requirements and the citation standard being used.

The parts of a source citation Four boxes side by side showing the parts of a source citation: the publisher, such as the World Bank; the dataset name, such as World Development Indicators; the date, such as accessed 2026-11-27; and the link, such as data.worldbank.org. Below: version or update date may also be required, depending on the provider and the citation standard. At the bottom: citing the source does not by itself prove the data is reliable, but it lets others find it, evaluate it and review the analysis. What goes into a source citation? Publisher World Bank Dataset name World Development Indicators Date accessed 2026-11-27 Link data.worldbank.org Version or update date may also be required, per the provider and citation standard Citing the source does not by itself prove the data is reliable, but it lets others find it, evaluate it and review your analysis
A good source line lets any reader reach exactly the data you used.

Does citing the source prove the data is reliable?

No. Citing the source does not by itself prove that the data is reliable. But it helps others find the data, evaluate it and review your analysis. The quality of the data and the method still need independent evaluation. Think of a chart shared online with no source: you have no idea where its numbers came from or how to check them. One source line turns it from a claim into something that can be checked.

Try It Yourself

Try
The journey of an API request
Put in order what happens when a weather app fetches the temperature from a service through an API, from start to finish.
1. The app (the client) sends the request to the endpoint
2. The server receives the request and processes it
3. The app reads the response
4. The server returns a response with the data in a format such as JSON, or an error message
5. The app prepares a request for the city of Aswan
6. The app shows the temperature or handles the error
Use the up and down buttons to move each step, then press Check.
Try
The internet access project
The situation
For a school project, you want to show how internet access in Egypt changed over ten years compared with two neighbouring countries, and the chart will be published on the school website. What do you do?
What would you do? You can try more than one choice.
Try
Key terms of the lesson
Tap a card to flip it and see the other side.

Common Mistakes

"If data is free and online, it is open"

Being public or free is not enough. Data is open when there is a licence or clear terms that allow access, reuse and redistribution.

Look for the licence or terms of use before assuming data is open.

"Open data doesn't need its terms checked"

Every dataset has its own terms, and datasets on the same site can differ.

Read that dataset's own terms and use it according to its licence.

"Whatever comes through an API isn't covered by the terms of use"

An API is only a way of accessing data; it does not change your rights to use it.

API access does not cancel the licence; respect request limits and storage and publishing policies.

"Citing the source proves the data is correct"

According to the Arabic edition, citing the source does not prove reliability by itself.

A citation lets others find the data, evaluate it and review the analysis; the data and the method still need independent evaluation.

"An API always returns data in JSON"

JSON is common but not the only format, and a response may be an error message rather than data.

The service decides the format, and the program must be ready to handle errors.

Key Points

  • Open data is available under a licence or terms that allow access, reuse and redistribution; being free does not make data open.
  • Before using it, check: source and quality, access method, licence, and fit to the question.
  • World Bank Open Data: country statistics (economy, population, education, health). UN Data: statistics from the UN and its agencies. Kaggle: a competition platform with varied datasets for studying machine learning.
  • An API is a set of rules that lets a program request data or functions from another service directly, without a browser, making repeated requests and automatic processing easier.
  • The sequence: the client sends a request to an endpoint, the server returns a response (data or an error message), and the program uses the data or handles the error.
  • JSON is a common text format (objects, arrays, values), but not the only one.
  • Citing the source: publisher, dataset name, version or update/access date, and link; it enables checking but does not prove reliability by itself.

FAQ

Is all data on the internet open data?

No. Data is open when its licence or terms explicitly allow access, reuse and redistribution. Being free or visible to everyone is not enough, so always look for the terms of use.

What is the difference between downloading data in a browser and using an API?

When downloading, you open the site and pick the file yourself. With an API, your program sends a request straight to the endpoint and receives the response automatically, which helps when repeating requests or handling lots of data. The same terms of use apply either way.

What should I write in a source line?

Whatever the provider and citation standard require: the publisher, the dataset name, the version or update or access date, and the link. The goal is that a reader can reach exactly the data you used.

Do I need to write a program to use open data?

No. Many sources offer a direct download in the browser. An API is an extra option that helps programs that need to fetch data automatically or repeatedly.

Done reading? Test yourself