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

HTTPX · Function

httpx.get

Sends a synchronous HTTP GET request using HTTPX's top-level API and returns its response. Optional arguments control query parameters, headers, authentication, redirects, TLS verification, timeouts, proxies, and environment settings.

How it works

httpx.get sends a synchronous GET request through HTTPX's top-level API and returns a Response. Request behavior can be adjusted with query parameters, headers, cookies, authentication, proxy settings, redirect handling, TLS verification, timeouts, and environment-variable trust.

Syntax

httpx.get(url, *, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

Parameters

NameTypeDescription
urlURL or URL-like valueRequest URL.
paramsoptional mapping or sequenceQuery-string parameters.
headersoptional mapping or sequenceAdditional request headers.
cookiesoptional cookie mappingCookies to send.
authoptional authentication valueAuthentication configuration.
proxyoptional proxy URL or configurationProxy configuration.
follow_redirectsbool, default FalseWhether to follow redirects.
verifybool or SSL configuration, default TrueWhether to verify TLS certificates.
timeoutTimeout or compatible value, default Timeout(timeout=5.0)Request timeout configuration.
trust_envbool, default TrueWhether to trust environment configuration such as proxy variables.

Returns

An httpx.Response instance.

Key points

  • The function issues an HTTP GET request and returns the resulting response.
  • Its public signature accepts a URL plus optional query parameters, headers, cookies, authentication, proxy, redirect, TLS, timeout, and environment settings.
  • Because the response is returned directly, the call can be chained with response methods such as raise_for_status().
  • Use params to encode values into the request URL's query string.
  • Use headers to attach additional HTTP headers to the outgoing request.
  • The returned response provides decoded text through its text-oriented response interface.

Common mistakes

  • Unlike request methods that carry a body, this convenience function does not accept data, files, JSON, or content arguments.
  • A returned response does not itself indicate that an HTTP error was raised; call raise_for_status() when unsuccessful status codes should become exceptions.

Example: GET with query parameters

import httpx

response = httpx.get(
    "https://httpbin.org/get",
    params={"q": "httpx"},
    headers={"user-agent": "learning-card/1.0"},
    timeout=5.0,
)
response.raise_for_status()
print(response.json()["args"]["q"])

Performs a GET request with query parameters and a header, then raises for an unsuccessful status before reading JSON.

When to use it

Fetch an HTTP resource

Retrieve a resource from an HTTP endpoint and inspect its status, headers, text, or JSON body.

Send query parameters

Build a GET URL with encoded filters, pagination, or search terms without manually formatting the query string.

Customize request context

Call an endpoint requiring custom metadata or authentication settings.

Interview questions

QWhat does httpx.get return?

httpx.get is the top-level synchronous convenience function for sending a GET request. It returns an HTTPX Response object, which can then be inspected or processed.

Follow-up: How would you make the request fail on a 4xx or 5xx response? Call response.raise_for_status() after receiving the response.

QHow do you add query parameters and headers?

Query-string values are supplied with params, and outgoing request metadata is supplied with headers. Both are keyword arguments on the function.

Follow-up: How would you prevent HTTPX from using environment-configured proxies? Pass trust_env=False to the top-level call.

QWhat are notable defaults for timeout and redirects?

The function uses a default timeout represented by Timeout(timeout=5.0), and redirects are not followed by default because follow_redirects=False. These defaults can be overridden per request.

Follow-up: How can a caller disable the timeout for one request? Pass timeout=None.

  • httpx.request
  • httpx.Client.get
  • httpx.post
  • httpx.delete
  • httpx.head
  • httpx.options
  • httpx.Response.raise_for_status

Source: Developer Interface - HTTPX. Checked 2026-10-15.