application programming interface (API) | Python Glossary – Real Python
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:
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.
For additional information on related topics, take a look at the following resources: