Client¶
- class impit.Client(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)¶
Synchronous 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).
- delete(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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:
- get(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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:
- head(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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:
- options(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make an 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:
- patch(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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:
- post(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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:
- put(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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:
- request(method, url, content=None, data=None, headers=None, timeout=None, force_http3=None, stream=False)¶
Make an 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 a streaming request with the specified method.
This method returns a context manager 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:
AbstractContextManager[Response]
- trace(url, content=None, data=None, headers=None, timeout=None, force_http3=None)¶
Make a 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: