What is Python's requests library?
Why Interviewers Ask This
Mid-level Python roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
requests is the most popular Python HTTP library for making web requests. Install: pip install requests. GET: response = requests.get("https://api.example.com/users"). POST with JSON: requests.post(url, json={"name": "Alice"}). Access response: response.status_code, response.json(), response.text, response.content (bytes), response.headers. Parameters: requests.get(url, params={"page": 1}). Headers: requests.get(url, headers={"Authorization": f"Bearer {token}"}). Timeout: requests.get(url, timeout=10) (always set timeouts). Authentication: requests.get(url, auth=("user", "pass")). Sessions (reuse connections, persist cookies): with requests.Session() as session: session.get(url). For async HTTP, use aiohttp or httpx (which supports both sync and async).
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.
Previous
What is pytest in Python?
Next
What is Python's virtual environment and dependency management?