kubex.client¶
Auto-generated reference for the kubex.client module.
BaseClient and factory¶
kubex.client.client ¶
BaseClient ¶
Bases: ABC
Source code in kubex/client/client.py
connect_websocket
async
¶
Open a WebSocket connection for a streaming subresource.
.. warning::
Experimental. The WebSocket transport (used by exec,
attach and portforward) is still under active development
and the surrounding API may change in future releases without
notice.
Source code in kubex/client/client.py
Client options¶
kubex.client.options ¶
ClientOptions ¶
Bases: BaseModel
Operational options for a kubex HTTP client.
These settings are per-process choices about how the HTTP client should
behave at request time. They do not come from kubeconfig or the in-cluster
environment — use :class:~kubex.configuration.ClientConfiguration for
those.
Example::
from kubex.client import ClientOptions, create_client
from kubex.core.params import Timeout
client = await create_client(
configuration=...,
options=ClientOptions(
log_api_warnings=False,
timeout=Timeout(total=30.0),
proxy="http://proxy.corp.example.com:8080",
keep_alive_timeout=60.0,
pool_size=50,
ws_max_message_size=8 * 1024 * 1024,
),
)
Backend asymmetries
Some fields are silently ignored on certain backends (a :class:UserWarning
is emitted at client construction time):
buffer_size: httpx has no equivalent buffer-size knob; the value is ignored and a warning is raised.pool_size_per_host: httpx has no per-host pool limit; the value is ignored and a warning is raised.keep_alive_timeout=None: aiohttp has no "unlimited keep-alive" mode. The value is ignored (aiohttp falls back to its own default) and a warning is raised.proxy=dict: aiohttp supports only a single session-level proxy URL. The entry whose key matches the API server's URL scheme is used; all other entries are dropped with a warning. httpx applies all dict entries viamounts=.
buffer_size
class-attribute
instance-attribute
¶
HTTP-response read buffer size in bytes.
Accepted values:
...(default) — kubex default of2**21bytes (preserves current aiohttp behavior).None— use the HTTP library's own default (aiohttp default:2**16bytes).int > 0— explicit buffer size in bytes.
Backend asymmetry: httpx has no equivalent buffer-size knob. This field
is ignored on httpx and a :class:UserWarning is emitted if it is not
....
keep_alive
class-attribute
instance-attribute
¶
Whether to reuse idle connections (connection keep-alive).
Set to False to close each connection immediately after use. This maps
to Limits(max_keepalive_connections=0) on httpx and
TCPConnector(force_close=True) on aiohttp.
keep_alive_timeout
class-attribute
instance-attribute
¶
Idle-connection lifetime in seconds.
Accepted values:
...(default) — use the HTTP library's own default (httpx: 5 s; aiohttp: 15 s).None— keep idle connections indefinitely. On httpx this passeskeepalive_expiry=None; on aiohttp this is not supported (aiohttp has no "unlimited" mode) and a :class:UserWarningis emitted.float >= 0— explicit lifetime in seconds.
log_api_warnings
class-attribute
instance-attribute
¶
Emit Python :mod:warnings for any Warning HTTP headers returned by
the API server.
The Kubernetes API server emits Warning: response headers to signal
deprecated API usage (e.g. calling a removed API version). When this is
True (the default), kubex converts each header value into a
:class:UserWarning via :func:warnings.warn. Set to False
to silence those warnings.
pool_size
class-attribute
instance-attribute
¶
Total connection pool size (all hosts combined).
Accepted values:
...(default) — use the HTTP library's own default (httpx: 100; aiohttp: 100).None— unlimited (passesNoneto httpx,0to aiohttp).int > 0— explicit connection limit.
pool_size_per_host
class-attribute
instance-attribute
¶
Per-host connection pool size.
Accepted values:
...(default) — use the HTTP library's own default (aiohttp: 0, meaning no per-host limit).None— unlimited (passes0to aiohttp).int > 0— explicit per-host connection limit.
Backend asymmetry: httpx has no per-host pool limit. This field is
ignored on httpx and a :class:UserWarning is emitted if it is not ....
proxy
class-attribute
instance-attribute
¶
Outbound HTTP proxy for all requests.
Accepted values:
None(default) — no proxy.str— a single proxy URL applied to every request, e.g."http://proxy.example.com:8080"or"http://user:[email protected]:8080"for basic auth.dict[str, str]— per-scheme map with"http"and/or"https"keys, e.g.{"https": "http://proxy.example.com:8080"}. Only"http"and"https"scheme keys are accepted.
Backend asymmetry: httpx routes all dict entries via mounts=;
aiohttp supports only a single session-level proxy URL, so only the entry
matching the API server's URL scheme is used (others are dropped with a
warning).
timeout
class-attribute
instance-attribute
¶
Default HTTP timeout for every request made by this client.
Accepted values:
...(default) — use the HTTP library's own default timeout.None— disable timeouts entirely.intorfloat— treat the value as atotaltimeout in seconds; coerced to :class:~kubex.core.params.Timeoutautomatically.- :class:
~kubex.core.params.Timeout— used as-is for fine-grained per-phase control.
Individual calls can override this via the request_timeout= parameter.
ws_max_message_size
class-attribute
instance-attribute
¶
Maximum WebSocket message size in bytes for exec/attach/portforward.
Accepted values:
...(default) — kubex default of2**21bytes (preserves current behavior on both backends).None— no cap on aiohttp (passes0tomax_msg_size). On httpx,Noneis not supported; falls back to httpx-ws default (65536 bytes) and a :class:UserWarningis emitted.int > 0— explicit cap in bytes.
resolve_ws_max_message_size ¶
Resolve ws_max_message_size to a concrete integer for HTTP backends.
...→2**21(kubex default; preserves pre-option behavior on both backends)None→0(aiohttp treats 0 as "no cap"; httpx does not pass this at all)int→ that int
Source code in kubex/client/options.py
WebSocket abstraction¶
kubex.client.websocket ¶
WebSocketConnection ¶
Bases: ABC
Async WebSocket connection abstraction used by exec/attach/port-forward.
Implementations adapt a concrete WebSocket client (e.g. aiohttp or
httpx-ws) to a uniform binary-frame interface. receive_bytes raises
StopAsyncIteration once the peer closes the connection. Non-binary
frames (e.g. text frames) are a protocol violation for the v5 channel
protocol; implementations must surface them as KubexClientException
rather than leaking backend-specific exceptions or silently coercing
them to bytes.
Httpx client¶
kubex.client.httpx ¶
HttpxWebSocketConnection ¶
HttpxWebSocketConnection(
cm: AbstractAsyncContextManager[AsyncWebSocketSession],
session: AsyncWebSocketSession,
)
Bases: WebSocketConnection
Adapter wrapping an :class:httpx_ws.AsyncWebSocketSession.
Source code in kubex/client/httpx.py
Aiohttp client¶
kubex.client.aiohttp ¶
AioHttpClient ¶
Bases: BaseClient
Source code in kubex/client/aiohttp.py
AioHttpWebSocketConnection ¶
Bases: WebSocketConnection
Adapter wrapping an :class:aiohttp.ClientWebSocketResponse.