API
A defined way for programs to talk to each other and exchange data.
An API (application programming interface) is a contract that lets one program request data or actions from another. On the web, you call an API by sending an HTTP request to a URL and usually get JSON back. In Python the requests library is the usual tool, and a status_code tells you whether it worked.
# with the requests package installed:
import requests
resp = requests.get("https://api.example.com/users/1")
if resp.status_code == 200:
user = resp.json() # parse JSON into a dict
print(user["name"])
Where this shows up in real Python
APIs power live data in your scripts: weather, prices, maps, payments, and your own web services.
Commonly used API tools
requests.get(url)— fetch data from an APIrequests.post(url, json=...)— send data.status_code— 200 OK, 404 not found, and so on.json()— parse the JSON responseparams={…}, headers={…}— query parameters and headers
Official documentation: requests: HTTP for Humans