requests — HTTP client

The requests module provides a minimal HTTP/HTTPS client API similar to the Python requests library. Each request function returns a requests.Response object.

Response class

class requests.Response(code: int, reason: str, headers: bytes = None, content: bytes = None)

Represents an HTTP response. Instances are returned by requests.request and the per-method helpers.

status_code: int

Integer HTTP status code returned by the server.

reason: str

Reason phrase returned by the server (decoded str).

encoding: str

String encoding used to decode requests.Response.headers and requests.Response.content. Defaults to "utf-8".

headers: str

Response headers decoded with requests.Response.encoding and returned as a str.

content: str

Response body decoded with requests.Response.encoding and returned as a str.

json() dict

Parse requests.Response.content as JSON and return the resulting object.

Functions

requests.request(method: str, url: str, data: bytes | None = None, json: Any | None = None, files: dict | None = None, headers: dict = {}, auth: tuple | None = None, stream: Any | None = None) Response

Send an HTTP request to url and return a requests.Response.

  • method — HTTP method as a str (e.g. "GET", "POST").

  • url — Target URL. Must start with http:// or https://.

  • data — Raw request body. If set, Content-Length is added automatically.

  • json — Object serialized to JSON and sent as the body. Sets Content-Type: application/json.

  • files — Dict mapping field name to a (filename, fileobj) tuple. Sent as multipart/form-data.

  • headers — Dict of additional request headers.

  • auth(username, password) tuple for HTTP Basic authentication.

  • stream — Accepted for API compatibility; not used.

requests.head(url: str, **kw) Response

Send a HEAD request. **kw is forwarded to requests.request.

requests.get(url: str, **kw) Response

Send a GET request. **kw is forwarded to requests.request.

requests.post(url: str, **kw) Response

Send a POST request. **kw is forwarded to requests.request.

requests.put(url: str, **kw) Response

Send a PUT request. **kw is forwarded to requests.request.

requests.patch(url: str, **kw) Response

Send a PATCH request. **kw is forwarded to requests.request.

requests.delete(url: str, **kw) Response

Send a DELETE request. **kw is forwarded to requests.request.