Fetch an HTTP resource
Retrieve a resource from an HTTP endpoint and inspect its status, headers, text, or JSON body.
HTTPX · Function
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.
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.
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)| Name | Type | Description |
|---|---|---|
url | URL or URL-like value | Request URL. |
params | optional mapping or sequence | Query-string parameters. |
headers | optional mapping or sequence | Additional request headers. |
cookies | optional cookie mapping | Cookies to send. |
auth | optional authentication value | Authentication configuration. |
proxy | optional proxy URL or configuration | Proxy configuration. |
follow_redirects | bool, default False | Whether to follow redirects. |
verify | bool or SSL configuration, default True | Whether to verify TLS certificates. |
timeout | Timeout or compatible value, default Timeout(timeout=5.0) | Request timeout configuration. |
trust_env | bool, default True | Whether to trust environment configuration such as proxy variables. |
An httpx.Response instance.
raise_for_status().params to encode values into the request URL's query string.headers to attach additional HTTP headers to the outgoing request.raise_for_status() when unsuccessful status codes should become exceptions.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.
Retrieve a resource from an HTTP endpoint and inspect its status, headers, text, or JSON body.
Build a GET URL with encoded filters, pagination, or search terms without manually formatting the query string.
Call an endpoint requiring custom metadata or authentication settings.
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.
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.
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.requesthttpx.Client.gethttpx.posthttpx.deletehttpx.headhttpx.optionshttpx.Response.raise_for_status