requests
noun
say it: “rih-KWESTS” /rɪˈkwɛsts/
A popular Python package for sending requests to websites and web APIs and reading the answers they send back.
What is the requests package?
requests is the Python package most programs use to call web APIs. requests.get sends a request and returns a
response whose status_code and json() you read. Install it with pip install requests.
import requests
url = "https://api.weather.gov/points/40.76,-111.89"
headers = {"User-Agent": "CampingTrip/1.0 (example@example.com)"}
response = requests.get(url, headers=headers, timeout=10)
print(response.status_code) # 200
print(response.json()["properties"]["forecast"]) # the forecast's address
In a sentence
- “After pip install requests, one line fetched the JSON.”
- “The camping script uses requests to fetch the weekend forecast.”
Level: Journeyman · More Python terms at this level
Updated