API reference¶
Generated from the package. These are the objects you import from redc.
Client and response¶
Client ¶
Client(base_url=None, read_buffer_size=16384, headers=None, persist_cookies=False, http_version='3', tls_version='default', tls_version_max='default', interface=None, unix_socket=None, ip_version='any', no_proxy=None, max_total_connections=1024, max_host_connections=64, max_idle_connections=2048, max_concurrent_streams=200, pool_min_size=16, pool_max_size=512, backend='asyncio', timeout=(30.0, 0.0), cert=None, verbose=None, raise_for_status=False, json_encoder=json_dumps, keep_alive=True)
RedC client for making HTTP requests
Initialize the RedC client
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL for the client. Default is |
None
|
read_buffer_size
|
int
|
The read buffer size for libcurl. Must be greater than |
16384
|
headers
|
dict
|
Headers to include in every request. Default is |
None
|
persist_cookies
|
bool
|
Whether to persist cookies across requests. Default is |
False
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
'3'
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
'default'
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
'default'
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
The URL still supplies the request path and |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
Default is |
'any'
|
no_proxy
|
str
|
Comma-separated hosts that skip |
None
|
max_total_connections
|
int
|
The maximum number of active TCP connections allowed simultaneously.
Set to |
1024
|
max_host_connections
|
int
|
The maximum number of active connections allowed per specific host.
Set to |
64
|
max_idle_connections
|
int
|
The maximum size of the network connection cache (Keep-Alive).
These are TCP connections kept open for reuse after a request completes.
Default is |
2048
|
max_concurrent_streams
|
int
|
The maximum number of concurrent streams allowed per HTTP/2 or HTTP/3 connection.
Default is |
200
|
pool_min_size
|
int
|
The number of internal request handles to pre-allocate during initialization to reduce startup latency.
Default is |
16
|
pool_max_size
|
int
|
The maximum number of reusable request handles to retain in the pool.
Excess handles created during high concurrency are destroyed rather than recycled.
Default is |
512
|
backend
|
`threaded` | `asyncio`, *optional*
|
Selects the execution backend used by RedC.
As a rule of thumb:
- Low concurrency → Default is |
'asyncio'
|
timeout
|
tuple
|
A tuple of |
(30.0, 0.0)
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification.
Default is |
None
|
verbose
|
bool
|
Force verbose output for all requests. Default is |
None
|
raise_for_status
|
bool
|
If |
False
|
json_encoder
|
Callable
|
A callable for encoding JSON data. Default is :class: |
json_dumps
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
True
|
Attributes¶
cookies
property
¶
Returns all stored session cookies as a dict
Returns:
| Type | Description |
|---|---|
|
|
is_running
property
¶
Checks if RedC is currently running
Returns:
| Type | Description |
|---|---|
|
|
Methods:¶
close ¶
Close the RedC client and free up resources.
This method must be called when the client is no longer needed to avoid memory leaks or unexpected behavior
delete ¶
delete(url, params=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, stream_callback=None, progress_callback=None, verbose=False, keep_alive=None)
Make a DELETE request
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the DELETE request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
stream_callback (
|
class: |
required | |
progress_callback (
|
class: |
required | |
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
get ¶
get(url, params=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, stream_callback=None, progress_callback=None, verbose=False, keep_alive=None)
Make a GET request
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the GET request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
stream_callback (
|
class: |
required | |
progress_callback (
|
class: |
required | |
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
get_cookies ¶
Retrieves currently stored session cookies
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
netscape
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Union[list[dict], list[str]]
|
|
head ¶
head(url, params=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, verbose=False, keep_alive=None)
Make a HEAD request
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the HEAD request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
options ¶
options(url, params=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, verbose=False, keep_alive=None)
Make an OPTIONS request
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the OPTIONS request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
patch ¶
patch(url, params=None, json=None, data=None, files=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, stream_callback=None, progress_callback=None, verbose=False, keep_alive=None)
Make a PATCH request
Examples:
>>> response = await client.patch(
... "/api/data/1",
... json={"key": "updated_value"},
... headers={"Authorization": "Bearer token"}
... )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the PATCH request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
json
|
Any
|
JSON data to send in the request body. Default is |
None
|
data
|
`dict` | `list[tuple]` | `bytes` | `str` | `BinaryIO`, *optional*
|
Data to send in the body of the Request.
- If a dict or list of tuples: Sends as |
None
|
files
|
dict
|
Dictionary of |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
stream_callback (
|
class: |
required | |
progress_callback (
|
class: |
required | |
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
post ¶
post(url, params=None, json=None, data=None, files=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, stream_callback=None, progress_callback=None, verbose=False, keep_alive=None)
Make a POST request
Examples:
>>> response = await client.post(
... "/api/data",
... json={"key": "value"},
... headers={"Authorization": "Bearer token"}
... )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the POST request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
json
|
Any
|
JSON data to send in the request body. Default is |
None
|
data
|
`dict` | `list[tuple]` | `bytes` | `str` | `BinaryIO`, *optional*
|
Data to send in the body of the Request.
- If a dict or list of tuples: Sends as |
None
|
files
|
dict
|
Dictionary of |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
stream_callback (
|
class: |
required | |
progress_callback (
|
class: |
required | |
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
put ¶
put(url, params=None, json=None, data=None, files=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, verify=True, auth=None, cert=None, stream_callback=None, progress_callback=None, verbose=False, keep_alive=None)
Make a PUT request
Examples:
>>> response = await client.put(
... "/api/data/1",
... json={"key": "new_value"},
... headers={"Authorization": "Bearer token"}
... )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the PUT request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
json
|
Any
|
JSON data to send in the request body. Default is |
None
|
data
|
`dict` | `list[tuple]` | `bytes` | `str` | `BinaryIO`, *optional*
|
Data to send in the body of the Request.
- If a dict or list of tuples: Sends as |
None
|
files
|
dict
|
Dictionary of |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
stream_callback (
|
class: |
required | |
progress_callback (
|
class: |
required | |
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
request ¶
request(method, url, params=None, json=None, data=None, files=None, headers=None, cookies=None, http_version=None, tls_version=None, tls_version_max=None, timeout=None, allow_redirects=True, proxy_url='', no_proxy=None, interface=None, unix_socket=None, ip_version=None, auth=None, verify=True, cert=None, stream_callback=None, progress_callback=None, verbose=False, keep_alive=None)
Make an HTTP request with the specified method and parameters
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The HTTP method to use (e.g., "GET", "POST") |
required |
url
|
str
|
The URL to send the request to or path if |
required |
params
|
`dict[str, str]` | `tuple[str, str]` | `str` | `bytes`, *optional*
|
Query parameters to include in the request. Default is |
None
|
json
|
dict
|
JSON data to send in the request body. Default is |
None
|
data
|
`dict` | `list[tuple]` | `bytes` | `str` | `BinaryIO`, *optional*
|
Data to send in the body of the Request.
- If a dict or list of tuples: Sends as |
None
|
files
|
dict
|
Dictionary of |
None
|
headers
|
dict[str, str]
|
Headers to include in the request. Default is |
None
|
cookies
|
dict[str, str]
|
Cookies to include in the request. Default is |
None
|
http_version
|
`auto` | `1` | `1.1` | `2` | `3`, *optional*
|
Preferred HTTP version to attempt; libcurl may downgrade version as needed. Default is |
None
|
tls_version
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Minimum TLS version (this version or later). |
None
|
tls_version_max
|
`default` | `1.0` | `1.1` | `1.2` | `1.3`, *optional*
|
Maximum TLS version. |
None
|
timeout
|
tuple
|
A tuple of |
None
|
allow_redirects
|
`bool` | `int`, *optional*
|
Whether to follow HTTP redirects. |
True
|
proxy_url
|
str
|
The proxy server URL to use for the request (e.g., |
''
|
no_proxy
|
str
|
Comma-separated hosts that skip the proxy and connect directly.
|
None
|
interface
|
str
|
Local interface name or IP address for outgoing connections.
|
None
|
unix_socket
|
str
|
Path of a Unix domain socket to connect to instead of the host in the URL.
When |
None
|
ip_version
|
`any` | `4` | `6`, *optional*
|
Which addresses of a hostname may be used. A numeric address in the URL is used as written.
When |
None
|
auth
|
`tuple` | `str`, *optional*
|
A tuple of |
None
|
verify
|
bool
|
Whether to verify SSL certificates. Default is |
True
|
cert
|
str
|
Path to a CA certificate bundle file for SSL/TLS verification. Default is |
None
|
stream_callback (
|
class: |
required | |
progress_callback (
|
class: |
required | |
verbose
|
bool
|
Whether to enable verbose output for the request. Default is |
False
|
keep_alive
|
bool
|
Whether to keep the underlying TCP connection alive after the request completes.
When |
None
|
Returns:
| Type | Description |
|---|---|
|
class: |
Response ¶
Response(status_code, headers, response, url, http_version, primary_ip, primary_port, local_ip, local_port, redirect_count, dns_time, connect_time, tls_time, first_byte_time, redirect_time, download_size, download_speed, upload_size, upload_speed, elapsed, curl_code, curl_error_message, verbose_output, raise_for_status=False)
Represents an HTTP response of RedC
Attributes¶
cookies
property
¶
Returns cookies set by the server (from Set-Cookie headers)
Collects cookies from all responses in the redirect chain.
If multiple Set-Cookie headers set the same cookie name, the last value wins.
Returns:
| Type | Description |
|---|---|
|
|
first_byte_time
property
¶
Time until the first response byte, in seconds, from the start of the transfer
is_permanent_redirect
property
¶
True if this response is a permanent redirect
links
property
¶
Returns the parsed Link HTTP header
Returns a list of dictionaries, where each dictionary contains the link
target (url) and other parameters (e.g., rel, title)
Returns:
| Type | Description |
|---|---|
|
|
redirect_time
property
¶
Time spent following redirects before the final transfer, in seconds
text
property
¶
Decodes the response content as a string using UTF-8
Returns:
| Type | Description |
|---|---|
|
|
verbose
property
¶
Raw verbose/debug output from libcurl (only when verbose=True on the request)
Methods:¶
decode ¶
Decodes the response content as a string using the specified encoding
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding
|
str
|
The encoding to use for decoding |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
raise_for_status ¶
Raises an :class:redc.exceptions.HTTPError or :class:redc.exceptions.CurlError if the response indicates an error
Callbacks¶
StreamCallback ¶
A class for creating a stream callback
A callback handler for streaming data
Examples:
>>> def callback(data: bytes, data_size: int):
... print(f"Received {len(data)}")
>>> stream_callback = StreamCallback(callback)
>>> client.get("https://example.com/", stream_callback=stream_callback)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[bytes, int], None]
|
A function that accepts two arguments: data (bytes) and data_size (int) The function cannot be asynchronous |
required |
ProgressCallback ¶
A class for creating a progress callback
A callback handler for progress updates
Examples:
>>> def callback(dltotal: int, dlnow: int, ultotal: int, ulnow: int):
... print(f"Downloaded {dlnow}/{dltotal}, Uploaded {ulnow}/{ultotal}")
>>> progress_callback = ProgressCallback(callback)
>>> client.get("https://example.com/", progress_callback=progress_callback)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[int, int, int, int], None]
|
A function that accepts four arguments: - dltotal (int): Total bytes expected to be downloaded - dlnow (int): Bytes downloaded so far - ultotal (int): Total bytes expected to be uploaded - ulnow (int): Bytes uploaded so far The function cannot be asynchronous. |
required |
URL¶
CurlURL ¶
URL parser and builder backed by libcurl.
Examples:
>>> u = CurlURL("https://user:pass@example.com:8080/path?q=1#frag")
>>> u.host
'example.com'
>>> u.port
8080
>>> u.path
'/path'
>>> u.query = None
>>> u["port"] = 443
>>> str(u)
'https://user:pass@example.com:443/path#frag'
Attributes:
| Name | Type | Description |
|---|---|---|
scheme |
str
|
URL scheme (e.g. |
user |
str
|
Username component of the URL. Returns |
password |
str
|
Password component of the URL. Returns |
options |
str
|
URL options component. Returns |
host |
str
|
Hostname or IP address. Returns |
zoneid |
str
|
IPv6 zone identifier. Returns |
port |
int
|
Port number. Returns |
path |
str
|
URL path. Returns |
query |
str
|
Query string without |
fragment |
str
|
Fragment without |
Notes
- All components can be modified or removed by assigning
None - Dict-style access is supported via
u["host"]and assignment viau["port"] = 443
init(self) -> None init(self, url: str) -> None
Overloaded function.
__init__(self) -> None
Create an empty URL object.
__init__(self, url: str) -> None
Create and parse a URL.
Args: url (str): URL to parse
Attributes¶
Methods:¶
get
method descriptor
¶
get(self, part: str, decode: bool = False, encode: bool = False, punycode: bool = False, empty: bool = False) -> object
Get a URL component dynamically.
Examples: >>> u.get("host") 'example.com' >>> u.get("path", decode=True)
Args:
part (str):
One of: scheme, user, password, options,
host, zoneid, port, path, query, fragment
decode (bool, optional):
Apply URL decoding. Default is `False`
encode (bool, optional):
Apply URL encoding. Default is `False`
punycode (bool, optional):
Convert host to punycode if applicable. Default is `False`
empty (bool, optional):
Return empty strings instead of `None` when supported by libcurl. Default is `False`
Returns:
str | int | None:
The requested component
is_valid_url ¶
is_valid_url(url: str) -> bool
Check if a URL is valid.
Args: url (str): URL to validate
Returns:
bool:
True if the URL is valid, otherwise False
parts
method descriptor
¶
parts(self) -> dict
Return all URL components as a dictionary.
Returns:
dict:
Mapping of all URL parts to their values (None if missing)
reset
method descriptor
¶
reset(self, url: str) -> None
Replace the current URL.
Args: url (str): New URL to parse
Status phrases¶
Errors¶
exceptions ¶
RedC exceptions
Classes¶
HTTPError ¶
CurlError ¶
Bases: builtins.Exception
Base class for all libcurl CURLcode errors
UnknownError ¶
UnsupportedProtocolError ¶
Bases: redc.exceptions.CurlError
The URL you passed to libcurl used a protocol that this libcurl does not support. The support might be a compile-time option that you did not use, it can be a misspelled protocol string or just a protocol libcurl has no code for
FailedInitError ¶
Bases: redc.exceptions.CurlError
Early initialization code failed. This is likely to be an internal error or problem, or a resource problem where something fundamental could not get done at init time
UrlMalformatError ¶
NotBuiltInError ¶
Bases: redc.exceptions.CurlError
A requested feature, protocol or option was not found built into this libcurl due to a build-time decision. This means that a feature or option was not enabled or explicitly disabled when libcurl was built and in order to get it to function you have to get a rebuilt libcurl
Attributes¶
message
class-attribute
¶
message = 'A requested feature, protocol or option was not found built into this libcurl due to a build-time decision. This means that a feature or option was not enabled or explicitly disabled when libcurl was built and in order to get it to function you have to get a rebuilt libcurl'
CouldntResolveProxyError ¶
CouldntResolveHostError ¶
CouldntConnectError ¶
WeirdServerReplyError ¶
Bases: redc.exceptions.CurlError
The server sent data libcurl could not parse. This error code was known as CURLE_FTP_WEIRD_SERVER_REPLY before 7.51.0
RemoteAccessDeniedError ¶
Bases: redc.exceptions.CurlError
We were denied access to the resource given in the URL. For FTP, this occurs while trying to change to the remote directory
FtpAcceptFailedError ¶
Bases: redc.exceptions.CurlError
While waiting for the server to connect back when an active FTP session is used, an error code was sent over the control connection or similar
FtpWeirdPassReplyError ¶
Bases: redc.exceptions.CurlError
After having sent the FTP password to the server, libcurl expects a proper reply. This error code indicates that an unexpected code was returned
FtpAcceptTimeoutError ¶
Bases: redc.exceptions.CurlError
During an active FTP session while waiting for the server to connect, the CURLOPT_ACCEPTTIMEOUT_MS (or the internal default) timeout expired
FtpWeirdPasvReplyError ¶
Bases: redc.exceptions.CurlError
libcurl failed to get a sensible result back from the server as a response to either a PASV or an EPSV command. The server is flawed
FtpWeird227FormatError ¶
Bases: redc.exceptions.CurlError
FTP servers return a 227-line as a response to a PASV command. If libcurl fails to parse that line, this return code is passed back
FtpCantGetHostError ¶
Http2Error ¶
Bases: redc.exceptions.CurlError
A problem was detected in the HTTP2 framing layer. This is somewhat generic and can be one out of several problems, see the error buffer for details
FtpCouldntSetTypeError ¶
PartialFileError ¶
Bases: redc.exceptions.CurlError
A file transfer was shorter or larger than expected. This happens when the server first reports an expected transfer size, and then delivers data that does not match the previously given size
FtpCouldntRetrFileError ¶
QuoteErrorError ¶
Bases: redc.exceptions.CurlError
When sending custom "QUOTE" commands to the remote server, one of the commands returned an error code that was 400 or higher (for FTP) or otherwise indicated unsuccessful completion of the command
HttpReturnedErrorError ¶
Bases: redc.exceptions.CurlError
This is returned if CURLOPT_FAILONERROR is set TRUE and the HTTP server returns an error code that is >= 400
WriteErrorError ¶
Bases: redc.exceptions.CurlError
An error occurred when writing received data to a local file, or an error was returned to libcurl from a write callback
UploadFailedError ¶
Bases: redc.exceptions.CurlError
Failed starting the upload. For FTP, the server typically denied the STOR command. The error buffer usually contains the server's explanation for this
ReadErrorError ¶
OutOfMemoryError ¶
Bases: redc.exceptions.CurlError
A memory allocation request failed. This is serious badness and things are severely screwed up if this ever occurs
OperationTimedoutError ¶
FtpPortFailedError ¶
Bases: redc.exceptions.CurlError
The FTP PORT command returned error. This mostly happens when you have not specified a good enough address for libcurl to use. See CURLOPT_FTPPORT
FtpCouldntUseRestError ¶
RangeErrorError ¶
SslConnectErrorError ¶
Bases: redc.exceptions.CurlError
A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others
BadDownloadResumeError ¶
FileCouldntReadFileError ¶
Bases: redc.exceptions.CurlError
A file given with FILE:// could not be opened. Most likely because the file path does not identify an existing file. Did you check file permissions?
LdapCannotBindError ¶
LdapSearchFailedError ¶
AbortedByCallbackError ¶
BadFunctionArgumentError ¶
InterfaceFailedError ¶
Bases: redc.exceptions.CurlError
Interface error. A specified outgoing interface could not be used. Set which interface to use for outgoing connections' source IP address with CURLOPT_INTERFACE
TooManyRedirectsError ¶
Bases: redc.exceptions.CurlError
Too many redirects. When following redirects, libcurl hit the maximum amount. Set your limit with CURLOPT_MAXREDIRS
UnknownOptionError ¶
Bases: redc.exceptions.CurlError
An option passed to libcurl is not recognized/known. Refer to the appropriate documentation. This is most likely a problem in the program that uses libcurl. The error buffer might contain more specific information about which exact option it concerns
Attributes¶
message
class-attribute
¶
message = 'An option passed to libcurl is not recognized/known. Refer to the appropriate documentation. This is most likely a problem in the program that uses libcurl. The error buffer might contain more specific information about which exact option it concerns'
SetoptOptionSyntaxError ¶
Bases: redc.exceptions.CurlError
An option passed in to a setopt was wrongly formatted. See error message for details about what option
GotNothingError ¶
Bases: redc.exceptions.CurlError
Nothing was returned from the server, and under the circumstances, getting nothing is considered an error
SslEngineNotfoundError ¶
SslEngineSetfailedError ¶
SendErrorError ¶
RecvErrorError ¶
SslCertproblemError ¶
SslCipherError ¶
PeerFailedVerificationError ¶
Bases: redc.exceptions.CurlError
The remote server's SSL certificate or SSH fingerprint was deemed not OK. This error code has been unified with CURLE_SSL_CACERT since 7.62.0. Its previous value was 51
BadContentEncodingError ¶
FilesizeExceededError ¶
UseSslFailedError ¶
SendFailRewindError ¶
Bases: redc.exceptions.CurlError
When doing a send operation curl had to rewind the data to retransmit, but the rewinding operation failed
SslEngineInitfailedError ¶
LoginDeniedError ¶
TftpNotfoundError ¶
TftpPermError ¶
RemoteDiskFullError ¶
TftpIllegalError ¶
TftpUnknownidError ¶
RemoteFileExistsError ¶
TftpNosuchuserError ¶
SslCacertBadfileError ¶
RemoteFileNotFoundError ¶
SshError ¶
SslShutdownFailedError ¶
AgainError ¶
Bases: redc.exceptions.CurlError
Socket is not ready for send/recv. Wait until it is ready and try again. This return code is only returned from curl_easy_recv and curl_easy_send
SslCrlBadfileError ¶
SslIssuerErrorError ¶
FtpPretFailedError ¶
Bases: redc.exceptions.CurlError
The FTP server does not understand the PRET command at all or does not support the given argument. Be careful when using CURLOPT_CUSTOMREQUEST, a custom LIST command is sent with the PRET command before PASV as well
Attributes¶
message
class-attribute
¶
message = 'The FTP server does not understand the PRET command at all or does not support the given argument. Be careful when using [CURLOPT_CUSTOMREQUEST](https://curl.se/libcurl/c/CURLOPT_CUSTOMREQUEST.html), a custom LIST command is sent with the PRET command before PASV as well'
RtspCseqErrorError ¶
RtspSessionErrorError ¶
FtpBadFileListError ¶
ChunkFailedError ¶
NoConnectionAvailableError ¶
Bases: redc.exceptions.CurlError
(For internal use only, is never returned by libcurl) No connection available, the session is queued
SslPinnedpubkeynotmatchError ¶
Bases: redc.exceptions.CurlError
Failed to match the pinned key specified with CURLOPT_PINNEDPUBLICKEY
SslInvalidcertstatusError ¶
Bases: redc.exceptions.CurlError
Status returned failure when asked with CURLOPT_SSL_VERIFYSTATUS
Http2StreamError ¶
RecursiveApiCallError ¶
AuthErrorError ¶
Http3Error ¶
Bases: redc.exceptions.CurlError
A problem was detected in the HTTP/3 layer. This is somewhat generic and can be one out of several problems, see the error buffer for details
QuicConnectErrorError ¶
Bases: redc.exceptions.CurlError
QUIC connection error. This error may be caused by an SSL library error. QUIC is the protocol used for HTTP/3 transfers
ProxyError ¶
Bases: redc.exceptions.CurlError
Proxy handshake error. CURLINFO_PROXY_ERROR provides extra details on the specific problem