AsyncClient¶
- class impit.AsyncClient(browser=None, http3=None, proxy=None, timeout=None, verify=None, default_encoding=None, follow_redirects=None, max_redirects=None, cookie_jar=None, cookies=None, headers=None, local_address=None)¶
Asynchronous HTTP client with browser impersonation capabilities.
- Parameters:
browser (Browser | None) –
Browser to impersonate (“chrome” or “firefox”).
If this is None (default), no impersonation is performed.
http3 (bool | None) –
If set to True, Impit will try to connect to the target servers using HTTP/3 protocol (if supported by the server).
Note
The HTTP/3 support is experimental and may not work with all servers. The impersonation capabilities are limited when using HTTP/3.
proxy (str | None) –
The proxy URL to use for all the requests made by this client.
This can be an HTTP, HTTPS, or SOCKS proxy.
timeout (float | None) –
Default request timeout in seconds.
This value can be overridden for individual requests.
verify (bool | None) –
If set to False, impit will not verify SSL certificates.
This can be used to ignore TLS errors (e.g., self-signed certificates).
True by default.
default_encoding (str | None) –
Default encoding for response.text field (e.g., “utf-8”, “cp1252”).
Overrides content-type headers and bytestream prescan.
follow_redirects (bool | None) –
If set to True the client will automatically follow HTTP redirects (3xx responses).
False by default.
max_redirects (int | None) –
Maximum number of redirects to follow if the follow_redirects option is enabled.
Default is 20.
cookie_jar (CookieJar | None) –
Cookie jar to store cookies in.
This is a http.cookiejar.CookieJar instance.
By default,
Client
doesn’t store cookies between requests.cookies (Cookies | None) –
httpx-compatible cookies object.
These are the cookies to include in all requests (to the matching servers) made by this client.
headers (dict[str, str] | None) –
Default HTTP headers to include in requests.
These headers will be included in all requests made by this client.
Default is an empty dictionary.
local_address (str | None) –
Local address to bind the client to.
Useful for testing purposes or when you want to bind the client to a specific network interface. Can be an IP address in the format xxx.xxx.xxx.xxx (for IPv4) or ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (for IPv6).
- async delete(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous DELETE request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async get(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous GET request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async head(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous HEAD request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async options(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous OPTIONS request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async patch(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous PATCH request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async post(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous POST request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async put(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous PUT request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
- async request(method, url, content=None, data=None, headers=None, timeout=None, force_http3=None, stream=False)¶
Make an asynchronous HTTP request with the specified method.
- Parameters:
method (str) – HTTP method (e.g., “get”, “post”)
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
stream (bool) – Whether to return a streaming response (default: False)
- Return type:
- stream(method, url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous streaming request with the specified method.
This method returns a AsyncContextManager that yields a streaming
Response
object.See the following example for usage:
with Client() as client: with client.stream("GET", "https://example.com/largefile") as response: for chunk in response.iter_bytes(): process(chunk) # Process each chunk as it is received
- Parameters:
method (str) – HTTP method (e.g., “get”, “post”)
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type:
AbstractAsyncContextManager[Response]
- async trace(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an asynchronous TRACE request.
- Parameters:
url (str) – URL to request
content (bytes | bytearray | list[int] | None) – Raw content to send
data (dict[str, str] | None) – Form data to send in request body
headers (dict[str, str] | None) – HTTP headers
timeout (float | None) – Request timeout in seconds (overrides default timeout)
force_http3 (bool | None) – Force HTTP/3 protocol
- Return type: