class documentation

class Client(BaseClient): (source)

View In Hierarchy

An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc. It can be shared between threads. 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. * **default_encoding** - *(optional)* The default encoding to use for decoding response text, if no charset information is included in a response Content-Type header. Set to a callable for automatic character set detection. Default: "utf-8".

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 _default_encoding 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): (source)

Undocumented

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

Undocumented

Parameters
exc_type:typing.Optional[typing.Type[BaseException]]Undocumented
exc_value:typing.Optional[BaseException]Undocumented
traceback:typing.Optional[TracebackType]Undocumented
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, default_encoding='utf-8'): (source)

Undocumented

Parameters
auth:typing.Optional[AuthTypes]Undocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
verify:VerifyTypesUndocumented
cert:typing.Optional[CertTypes]Undocumented
http1:boolUndocumented
http2:boolUndocumented
proxies:typing.Optional[ProxiesTypes]Undocumented
mounts:typing.Optional[typing.Mapping[str, BaseTransport]]Undocumented
timeout:TimeoutTypesUndocumented
follow_redirects:boolUndocumented
limits:LimitsUndocumented
max_redirects:intUndocumented
event_hooks:typing.Optional[typing.Mapping[str, typing.List[EventHook]]]Undocumented
base_url:URLTypesUndocumented
transport:typing.Optional[BaseTransport]Undocumented
app:typing.Optional[typing.Callable[..., typing.Any]]Undocumented
trust_env:boolUndocumented
default_encoding:typing.Union[str, typing.Callable[[bytes], str]]Undocumented
def close(self): (source)

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): (source)

Send a `DELETE` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Send a `GET` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Send a `HEAD` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Send an `OPTIONS` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Send a `PATCH` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
content:typing.Optional[RequestContent]Undocumented
data:typing.Optional[RequestData]Undocumented
files:typing.Optional[RequestFiles]Undocumented
json:typing.Optional[typing.Any]Undocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Send a `POST` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
content:typing.Optional[RequestContent]Undocumented
data:typing.Optional[RequestData]Undocumented
files:typing.Optional[RequestFiles]Undocumented
json:typing.Optional[typing.Any]Undocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Send a `PUT` request. **Parameters**: See `httpx.request`.

Parameters
url:URLTypesUndocumented
content:typing.Optional[RequestContent]Undocumented
data:typing.Optional[RequestData]Undocumented
files:typing.Optional[RequestFiles]Undocumented
json:typing.Optional[typing.Any]Undocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

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:typing.Optional[RequestContent]Undocumented
data:typing.Optional[RequestData]Undocumented
files:typing.Optional[RequestFiles]Undocumented
json:typing.Optional[typing.Any]Undocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault, None]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
Returns
ResponseUndocumented
def send(self, request, *, stream=False, auth=USE_CLIENT_DEFAULT, follow_redirects=USE_CLIENT_DEFAULT): (source)

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, None]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): (source)

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:typing.Optional[RequestContent]Undocumented
data:typing.Optional[RequestData]Undocumented
files:typing.Optional[RequestFiles]Undocumented
json:typing.Optional[typing.Any]Undocumented
params:typing.Optional[QueryParamTypes]Undocumented
headers:typing.Optional[HeaderTypes]Undocumented
cookies:typing.Optional[CookieTypes]Undocumented
auth:typing.Union[AuthTypes, UseClientDefault, None]Undocumented
follow_redirects:typing.Union[bool, UseClientDefault]Undocumented
timeout:typing.Union[TimeoutTypes, UseClientDefault]Undocumented
extensions:typing.Optional[RequestExtensions]Undocumented
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): (source)

Undocumented

Parameters
proxy:ProxyUndocumented
verify:VerifyTypesUndocumented
cert:typing.Optional[CertTypes]Undocumented
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): (source)

Undocumented

Parameters
verify:VerifyTypesUndocumented
cert:typing.Optional[CertTypes]Undocumented
http1:boolUndocumented
http2:boolUndocumented
limits:LimitsUndocumented
transport:typing.Optional[BaseTransport]Undocumented
app:typing.Optional[typing.Callable[..., typing.Any]]Undocumented
trust_env:boolUndocumented
Returns
BaseTransportUndocumented
def _send_handling_auth(self, request, auth, follow_redirects, history): (source)

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): (source)

Undocumented

Parameters
request:RequestUndocumented
follow_redirects:boolUndocumented
history:typing.List[Response]Undocumented
Returns
ResponseUndocumented
def _send_single_request(self, request): (source)

Sends a single request, without handling any redirections.

Parameters
request:RequestUndocumented
Returns
ResponseUndocumented
def _transport_for_url(self, url): (source)

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

Undocumented

_transport = (source)

Undocumented