1.3 KiB
1.3 KiB
Requests Compatibility Guide
HTTPX aims to be compatible with the requests API wherever possible.
This documentation outlines places where the API differs...
QuickStart
Pretty much any API mentioned in the requests QuickStart should be identical
to the API in our own documentation. The following exceptions apply:
Response.url- Returns aURLinstance, rather than a string. Usestr(response.url)if you need a string instance.httpx.codes- In our documentation we prefer the uppercased versions, such ascodes.NOT_FOUND, but also provide lower-cased versions for API compatibility withrequests.stream=True. - Streaming responses provide the.stream()and.raw()byte iterator interfaces, rather than the.iter_content()method and the.rawsocket interface..get,.delete,.head,.options- These methods do not supportfiles,data, orjsonarguments. Use.requestif you need to need to send data using these http methods.
Advanced Usage
requests.Session
The HTTPX equivalent of requests.Session is httpx.Client.
session = requests.Session(**kwargs)
is equivalent to
client = httpx.Client(**kwargs)
More detailed documentation and usage of Client can be found in Advanced Usage.