class documentation

class Client(BaseClient):

View In Hierarchy

An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.

Usage:

`python >>> client = httpx.Client() >>> response = client.get('https://example.org') `

Parameters:

  • auth - (optional) An authentication class to use when sending

requests. * params - (optional) Query parameters to include in request URLs, as a string, dictionary, or sequence of two-tuples. * headers - (optional) Dictionary of HTTP headers to include when sending requests. * cookies - (optional) Dictionary of Cookie items to include when sending requests. * verify - (optional) SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. Either True (default CA bundle), a path to an SSL certificate file, an ssl.SSLContext, or False (which will disable verification). * cert - (optional) An SSL certificate used by the requested host to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file), or a three-tuple of (certificate file, key file, password). * proxies - (optional) A dictionary mapping proxy keys to proxy URLs. * timeout - (optional) The timeout configuration to use when sending requests. * limits - (optional) The limits configuration to use. * max_redirects - (optional) The maximum number of redirect responses that should be followed. * base_url - (optional) A URL to use as the base when building request URLs. * transport - (optional) A transport class to use for sending requests over the network. * app - (optional) An WSGI application to send requests to, rather than sending actual network requests. * trust_env - (optional) Enables or disables usage of environment variables for configuration.

Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method close Close transport and proxies.
Method delete Send a DELETE request.
Method get Send a GET request.
Method head Send a HEAD request.
Method options Send an OPTIONS request.
Method patch Send a PATCH request.
Method post Send a POST request.
Method put Send a PUT request.
Method request Build and send a request.
Method send Send a request.
Method stream Alternative to httpx.request() that streams the response body instead of loading it into memory at once.
Method ​_init​_proxy​_transport Undocumented
Method ​_init​_transport Undocumented
Method ​_send​_handling​_auth Undocumented
Method ​_send​_handling​_redirects Undocumented
Method ​_send​_single​_request Sends a single request, without handling any redirections.
Method ​_transport​_for​_url Returns the transport instance that should be used for a given URL. This will either be the standard connection pool, or a proxy.
Instance Variable ​_mounts Undocumented
Instance Variable ​_state Undocumented
Instance Variable ​_transport Undocumented

Inherited from BaseClient:

Method auth.setter Undocumented
Method base​_url.setter Undocumented
Method build​_request Build and return a request instance.
Method cookies.setter Undocumented
Method event​_hooks.setter Undocumented
Method headers.setter Undocumented
Method params.setter Undocumented
Method timeout.setter Undocumented
Instance Variable follow​_redirects Undocumented
Instance Variable max​_redirects Undocumented
Property auth Authentication class used when none is passed at the request-level.
Property base​_url Base URL to use when sending requests with relative URLs.
Property cookies Cookie values to include when sending requests.
Property event​_hooks Undocumented
Property headers HTTP headers to include when sending requests.
Property is​_closed Check if the client being closed
Property params Query parameters to include in the URL when sending requests.
Property timeout Undocumented
Property trust​_env Undocumented
Method ​_build​_auth Undocumented
Method ​_build​_redirect​_request Given a request and a redirect response, return a new request that should be used to effect the redirect.
Method ​_build​_request​_auth Undocumented
Method ​_enforce​_trailing​_slash Undocumented
Method ​_get​_proxy​_map Undocumented
Method ​_merge​_cookies Merge a cookies argument together with any cookies on the client, to create the cookies used for the outgoing request.
Method ​_merge​_headers Merge a headers argument together with any headers on the client, to create the headers used for the outgoing request.
Method ​_merge​_queryparams Merge a queryparams argument together with any queryparams on the client, to create the queryparams used for the outgoing request.
Method ​_merge​_url Merge a URL argument together with any 'base_url' on the client, to create the URL used for the outgoing request.
Method ​_redirect​_headers Return the headers that should be used for the redirect request.
Method ​_redirect​_method When being redirected we may want to change the method of the request based on certain specs or browser behavior.
Method ​_redirect​_stream Return the body that should be used for the redirect request.
Method ​_redirect​_url Return the URL for the redirect to follow.
Instance Variable ​_auth Undocumented
Instance Variable ​_base​_url Undocumented
Instance Variable ​_cookies Undocumented
Instance Variable ​_event​_hooks Undocumented
Instance Variable ​_headers Undocumented
Instance Variable ​_netrc Undocumented
Instance Variable ​_params Undocumented
Instance Variable ​_timeout Undocumented
Instance Variable ​_trust​_env Undocumented
def __enter__(self):

Undocumented

Returns
TUndocumented
def __exit__(self, exc_type=None, exc_value=None, traceback=None):

Undocumented

Parameters
exc​_type:typing.Type[BaseException]Undocumented
exc​_value:BaseExceptionUndocumented
traceback:TracebackTypeUndocumented
def __init__(self, *, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, http1=True, http2=False, proxies=None, mounts=None, timeout=DEFAULT_TIMEOUT_CONFIG, follow_redirects=False, limits=DEFAULT_LIMITS, max_redirects=DEFAULT_MAX_REDIRECTS, event_hooks=None, base_url='', transport=None, app=None, trust_env=True):

Undocumented

Parameters
auth:AuthTypesUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
verify:VerifyTypesUndocumented
cert:CertTypesUndocumented
http1:boolUndocumented
http2:boolUndocumented
proxies:ProxiesTypesUndocumented
mounts:typing.Mapping[str, BaseTransport]Undocumented
timeout:TimeoutTypesUndocumented
follow​_redirects:boolUndocumented
limits:LimitsUndocumented
max​_redirects:intUndocumented
event​_hooks:typing.Mapping[str, typing.List[typing.Callable]]Undocumented
base​_url:URLTypesUndocumented
transport:BaseTransportUndocumented
app:typing.CallableUndocumented
trust​_env:boolUndocumented
def close(self):
Close transport and proxies.
def delete(self, url, *, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send a DELETE request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def get(self, url, *, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send a GET request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def head(self, url, *, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send a HEAD request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def options(self, url, *, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send an OPTIONS request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def patch(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send a PATCH request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
content:RequestContentUndocumented
data:RequestDataUndocumented
files:RequestFilesUndocumented
json:typing.AnyUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def post(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send a POST request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
content:RequestContentUndocumented
data:RequestDataUndocumented
files:RequestFilesUndocumented
json:typing.AnyUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def put(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Send a PUT request.

Parameters: See httpx.request.

Parameters
url:URLTypesUndocumented
content:RequestContentUndocumented
data:RequestDataUndocumented
files:RequestFilesUndocumented
json:typing.AnyUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def request(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Build and send a request.

Equivalent to:

`python request = client.build_request(...) response = client.send(request, ...) `

See Client.build_request(), Client.send() and [Merging of configuration][0] for how the various parameters are merged with client-level configuration.

[0]: /advanced/#merging-of-configuration

Parameters
method:strUndocumented
url:URLTypesUndocumented
content:RequestContentUndocumented
data:RequestDataUndocumented
files:RequestFilesUndocumented
json:typing.AnyUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
ResponseUndocumented
def send(self, request, *, stream=False, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT):

Send a request.

The request is sent as-is, unmodified.

Typically you'll want to build one with Client.build_request() so that any client-level configuration is merged into the request, but passing an explicit httpx.Request() is supported as well.

See also: [Request instances][0]

[0]: /advanced/#request-instances

Parameters
request:RequestUndocumented
stream:boolUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
Returns
ResponseUndocumented
@contextmanager
def stream(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT, timeout=USE_CLIENT_DEFAULT, extensions=None):

Alternative to httpx.request() that streams the response body instead of loading it into memory at once.

Parameters: See httpx.request.

See also: [Streaming Responses][0]

[0]: /quickstart#streaming-responses

Parameters
method:strUndocumented
url:URLTypesUndocumented
content:RequestContentUndocumented
data:RequestDataUndocumented
files:RequestFilesUndocumented
json:typing.AnyUndocumented
params:QueryParamTypesUndocumented
headers:HeaderTypesUndocumented
cookies:CookieTypesUndocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow​_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:dictUndocumented
Returns
typing.Iterator[Response]Undocumented
def _init_proxy_transport(self, proxy, verify=True, cert=None, http1=True, http2=False, limits=DEFAULT_LIMITS, trust_env=True):

Undocumented

Parameters
proxy:ProxyUndocumented
verify:VerifyTypesUndocumented
cert:CertTypesUndocumented
http1:boolUndocumented
http2:boolUndocumented
limits:LimitsUndocumented
trust​_env:boolUndocumented
Returns
BaseTransportUndocumented
def _init_transport(self, verify=True, cert=None, http1=True, http2=False, limits=DEFAULT_LIMITS, transport=None, app=None, trust_env=True):

Undocumented

Parameters
verify:VerifyTypesUndocumented
cert:CertTypesUndocumented
http1:boolUndocumented
http2:boolUndocumented
limits:LimitsUndocumented
transport:BaseTransportUndocumented
app:typing.CallableUndocumented
trust​_env:boolUndocumented
Returns
BaseTransportUndocumented
def _send_handling_auth(self, request, auth, follow_redirects, history):

Undocumented

Parameters
request:RequestUndocumented
auth:AuthUndocumented
follow​_redirects:boolUndocumented
history:typing.List[Response]Undocumented
Returns
ResponseUndocumented
def _send_handling_redirects(self, request, follow_redirects, history):

Undocumented

Parameters
request:RequestUndocumented
follow​_redirects:boolUndocumented
history:typing.List[Response]Undocumented
Returns
ResponseUndocumented
def _send_single_request(self, request):
Sends a single request, without handling any redirections.
Parameters
request:RequestUndocumented
Returns
ResponseUndocumented
def _transport_for_url(self, url):
Returns the transport instance that should be used for a given URL. This will either be the standard connection pool, or a proxy.
Parameters
url:URLUndocumented
Returns
BaseTransportUndocumented
_mounts =

Undocumented

_state =

Undocumented

_transport =

Undocumented