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 structures 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)
In this tutorial on Python's Requests library, you'll see some of the most useful features that Requests has to offer as well as ways to customize and optimize those features. You'll learn how to use requests efficiently and stop requests to external services from slowing down your application.
For additional information on related topics, take a look at the following resources:
By Leodanis Pozo Ramos • Updated May 21, 2025