application programming interface (API)
In programming, an application programming interface (API) is a set of rules and protocols that allows different software applications to communicate with each other.
APIs define the methods and data attributes that developers can use to interact with external software components, operating systems, or microservices.
When you use an API, you’re leveraging predefined functions to send requests and receive responses, enabling your application to perform tasks or retrieve data without needing to know the intricate details of how those tasks are executed internally.
Example
Web APIs are a common example of a concrete type of API. Here’s an example where you use the requests
library to interact with a freely available API that provides information about cats:
>>> import requests
>>> response = requests.get("https://api.thecatapi.com/v1/breeds")
>>> if response.status_code == 200:
... data = response.json()
... print(data[0])
... else:
... print(f"Failed to retrieve data: {response.status_code}")
...
{
'weight': {'imperial': '7 - 10', 'metric': '3 - 5'},
'id': 'abys',
'name': 'Abyssinian',
...
In this example, you send a GET request to an API endpoint and check if the response is successful using a status code. If so, you parse the JSON data returned by the API and print out a portion of it. This is a quick demonstration of how you can interact with a web API to retrieve information.
Related Resources
Tutorial
Python's Requests Library (Guide)
The Requests library is the go-to tool for making HTTP requests in Python. Learn how to use its intuitive API to send requests and interact with the web.
For additional information on related topics, take a look at the following resources:
- Python & APIs: A Winning Combo for Reading Public Data (Tutorial)
- Making HTTP Requests With Python (Course)
- Python's Requests Library (Quiz)
By Leodanis Pozo Ramos • Updated July 4, 2025