Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Requests · Function

requests.get

Sends an HTTP GET request and returns a requests.Response. Query-string data goes in params; other request options are supplied as keyword arguments.

How it works

requests.get creates and sends a GET request for the supplied URL. It can add query parameters and accepts the optional keyword arguments supported by requests.request; the returned Response exposes the server's result.

Syntax

requests.get(url, params=None, **kwargs)

Parameters

NameTypeDescription
urlUriTypeURL for the new Request object.
paramsParamsType | NoneOptional dictionary, list of tuples, or bytes to send in the request query string.
**kwargsGetKwargsOptional keyword arguments accepted by request.

Returns

A Response object; return type requests.Response.

Key points

  • Use this function when the intended HTTP method is GET.
  • url specifies the resource for which Requests constructs the request.
  • params encodes query-string values and supports mappings, repeated-key tuples, or raw bytes.
  • kwargs provides the optional controls accepted by the general request function.

Common mistakes

  • A response body is normally downloaded immediately; use stream=True when you need to defer body retrieval.
  • Streaming changes response-body handling, so close the response when finished, preferably with a context manager.

Example: GET a resource with query parameters

import requests

response = requests.get(
    "https://httpbin.org/get",
    params={"page": 2},
    timeout=10,
)
response.raise_for_status()
print(response.json())

This sends a GET request with query parameters, checks for an HTTP error, and reads the JSON response.

When to use it

Fetch a resource

Retrieve a web resource or API endpoint using the GET method.

Build query parameters

Add filters, pagination, or other query-string values without manually building the URL.

Customize the request

Apply shared request options such as headers, authentication, timeout, or streaming.

Interview questions

QWhat does requests.get return?

requests.get is a convenience function for issuing an HTTP GET request. It returns a requests.Response object, which contains the server response and the original request.

Follow-up: How would you avoid downloading the body immediately? Pass stream=True, then consume the response and close it when done.

QWhat are the main positional arguments?

url identifies the resource, while params supplies query-string data. The documentation allows params to be a dictionary, a list of tuples, or bytes.

Follow-up: Why use a list of tuples? It preserves repeated query-key entries, which a plain dictionary cannot represent directly.

QHow can request behavior be customized?

Additional keyword arguments are forwarded through the request machinery, so options such as authentication, headers, redirects, streaming, and timeouts can be supplied. A timeout should be provided when an application must not wait indefinitely.

Follow-up: What happens with stream=True? The body is deferred until accessed, and the response must be closed after use.

  • requests.request
  • requests.Session.get
  • requests.Response
  • requests.Request

Source: Developer Interface — Requests 2.34.2 documentation. Checked 2026-10-15.