class AsyncClient(BaseClient): (source)
An asynchronous HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc. Usage: ```python >>> async with httpx.AsyncClient() as client: >>> response = await 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, or `False` (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). * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be enabled. Defaults to `False`. * **proxies** - *(optional)* A dictionary mapping HTTP protocols 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 ASGI 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".
Async Method | __aenter__ |
Undocumented |
Async Method | __aexit__ |
Undocumented |
Method | __init__ |
Undocumented |
Async Method | aclose |
Close transport and proxies. |
Async Method | delete |
Send a `DELETE` request. |
Async Method | get |
Send a `GET` request. |
Async Method | head |
Send a `HEAD` request. |
Async Method | options |
Send an `OPTIONS` request. |
Async Method | patch |
Send a `PATCH` request. |
Async Method | post |
Send a `POST` request. |
Async Method | put |
Send a `PUT` request. |
Async Method | request |
Build and send a request. |
Async Method | send |
Send a request. |
Async Method | stream |
Alternative to `httpx.request()` that streams the response body instead of loading it into memory at once. |
Method | _init |
Undocumented |
Method | _init |
Undocumented |
Async Method | _send |
Undocumented |
Async Method | _send |
Undocumented |
Async Method | _send |
Sends a single request, without handling any redirections. |
Method | _transport |
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 |
Undocumented |
Method | base |
Undocumented |
Method | build |
Build and return a request instance. |
Method | cookies |
Undocumented |
Method | event |
Undocumented |
Method | headers |
Undocumented |
Method | params |
Undocumented |
Method | timeout |
Undocumented |
Instance Variable | follow |
Undocumented |
Instance Variable | max |
Undocumented |
Property | auth |
Authentication class used when none is passed at the request-level. |
Property | base |
Base URL to use when sending requests with relative URLs. |
Property | cookies |
Cookie values to include when sending requests. |
Property | event |
Undocumented |
Property | headers |
HTTP headers to include when sending requests. |
Property | is |
Check if the client being closed |
Property | params |
Query parameters to include in the URL when sending requests. |
Property | timeout |
Undocumented |
Property | trust |
Undocumented |
Method | _build |
Undocumented |
Method | _build |
Given a request and a redirect response, return a new request that should be used to effect the redirect. |
Method | _build |
Undocumented |
Method | _enforce |
Undocumented |
Method | _get |
Undocumented |
Method | _merge |
Merge a cookies argument together with any cookies on the client, to create the cookies used for the outgoing request. |
Method | _merge |
Merge a headers argument together with any headers on the client, to create the headers used for the outgoing request. |
Method | _merge |
Merge a queryparams argument together with any queryparams on the client, to create the queryparams used for the outgoing request. |
Method | _merge |
Merge a URL argument together with any 'base_url' on the client, to create the URL used for the outgoing request. |
Method | _redirect |
Return the headers that should be used for the redirect request. |
Method | _redirect |
When being redirected we may want to change the method of the request based on certain specs or browser behavior. |
Method | _redirect |
Return the body that should be used for the redirect request. |
Method | _redirect |
Return the URL for the redirect to follow. |
Instance Variable | _auth |
Undocumented |
Instance Variable | _base |
Undocumented |
Instance Variable | _cookies |
Undocumented |
Instance Variable | _default |
Undocumented |
Instance Variable | _event |
Undocumented |
Instance Variable | _headers |
Undocumented |
Instance Variable | _netrc |
Undocumented |
Instance Variable | _params |
Undocumented |
Instance Variable | _timeout |
Undocumented |
Instance Variable | _trust |
Undocumented |
Undocumented
Parameters | |
exctyping.Optional[ | Undocumented |
exctyping.Optional[ | Undocumented |
traceback:typing.Optional[ | Undocumented |
httpx._client.BaseClient.__init__
Undocumented
Parameters | |
auth:typing.Optional[ | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
verify:VerifyTypes | Undocumented |
cert:typing.Optional[ | Undocumented |
http1:bool | Undocumented |
http2:bool | Undocumented |
proxies:typing.Optional[ | Undocumented |
mounts:typing.Optional[ | Undocumented |
timeout:TimeoutTypes | Undocumented |
followbool | Undocumented |
limits:Limits | Undocumented |
maxint | Undocumented |
eventtyping.Optional[ | Undocumented |
baseURLTypes | Undocumented |
transport:typing.Optional[ | Undocumented |
app:typing.Optional[ | Undocumented |
trustbool | Undocumented |
defaulttyping.Union[ | Undocumented |
Send a `DELETE` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send a `GET` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send a `HEAD` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send an `OPTIONS` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send a `PATCH` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
content:typing.Optional[ | Undocumented |
data:typing.Optional[ | Undocumented |
files:typing.Optional[ | Undocumented |
json:typing.Optional[ | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send a `POST` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
content:typing.Optional[ | Undocumented |
data:typing.Optional[ | Undocumented |
files:typing.Optional[ | Undocumented |
json:typing.Optional[ | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send a `PUT` request. **Parameters**: See `httpx.request`.
Parameters | |
url:URLTypes | Undocumented |
content:typing.Optional[ | Undocumented |
data:typing.Optional[ | Undocumented |
files:typing.Optional[ | Undocumented |
json:typing.Optional[ | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Build and send a request. Equivalent to: ```python request = client.build_request(...) response = await client.send(request, ...) ``` See `AsyncClient.build_request()`, `AsyncClient.send()` and [Merging of configuration][0] for how the various parameters are merged with client-level configuration. [0]: /advanced/#merging-of-configuration
Parameters | |
method:str | Undocumented |
url:URLTypes | Undocumented |
content:typing.Optional[ | Undocumented |
data:typing.Optional[ | Undocumented |
files:typing.Optional[ | Undocumented |
json:typing.Optional[ | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
Response | Undocumented |
Send a request. The request is sent as-is, unmodified. Typically you'll want to build one with `AsyncClient.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:Request | Undocumented |
stream:bool | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
Returns | |
Response | Undocumented |
async 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:str | Undocumented |
url:URLTypes | Undocumented |
content:typing.Optional[ | Undocumented |
data:typing.Optional[ | Undocumented |
files:typing.Optional[ | Undocumented |
json:typing.Optional[ | Undocumented |
params:typing.Optional[ | Undocumented |
headers:typing.Optional[ | Undocumented |
cookies:typing.Optional[ | Undocumented |
auth:typing.Union[ | Undocumented |
followtyping.Union[ | Undocumented |
timeout:typing.Union[ | Undocumented |
extensions:typing.Optional[ | Undocumented |
Returns | |
typing.AsyncIterator[ | Undocumented |
Undocumented
Parameters | |
proxy:Proxy | Undocumented |
verify:VerifyTypes | Undocumented |
cert:typing.Optional[ | Undocumented |
http1:bool | Undocumented |
http2:bool | Undocumented |
limits:Limits | Undocumented |
trustbool | Undocumented |
Returns | |
AsyncBaseTransport | Undocumented |
Undocumented
Parameters | |
verify:VerifyTypes | Undocumented |
cert:typing.Optional[ | Undocumented |
http1:bool | Undocumented |
http2:bool | Undocumented |
limits:Limits | Undocumented |
transport:typing.Optional[ | Undocumented |
app:typing.Optional[ | Undocumented |
trustbool | Undocumented |
Returns | |
AsyncBaseTransport | Undocumented |
Undocumented
Parameters | |
request:Request | Undocumented |
followbool | Undocumented |
history:typing.List[ | Undocumented |
Returns | |
Response | Undocumented |
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:URL | Undocumented |
Returns | |
AsyncBaseTransport | Undocumented |