Skip to content
BENIBIX Learn

Requests (Python)

Development🔌 APIsHTTP Clients

Also known as Python Requests, requests library, import requests

A Python tool for calling web APIs. One line gets a page.

Think of it like

Think of it like a polite messenger. You say where to go and what to ask, and it brings back the answer.

Example

Lucy writes a Python script with Requests. Every hour it asks a weather API for the forecast and saves it.

Why it matters

It is the usual way Python code talks to the web.

Definition

Requests is a popular Python library for sending HTTP requests. One line can fetch a page or call an API. It handles headers, cookies and JSON for you. Its motto is HTTP for Humans, because it is simple to read. Scripts, scrapers and back ends all use it.

Example code

python
import requests

res = requests.get("https://api.example.com/orders/42", timeout=10)
print(res.status_code, res.json()["total"])
Fetch an order, with a time limit, and read the JSON.
Requests sends the same request from Python.

Common mistake

Leaving out a timeout. Without one, a call to a stuck server can hang forever.

Key takeaways

  1. 1
    One line. requests.get fetches it.
  2. 2
    JSON built in. res.json() reads the body.
  3. 3
    Set a timeout. Never wait forever.