Asynchronous Kubernetes client inspired by kube.rs
Project description
Kubex
Kubex is a Kubernetes client library for Python inspired by kube.rs. It is built on top of Pydantic and is async-runtime agnostic.
Why Kubex?
Performance
Kubex is dramatically faster than kubernetes-asyncio, the most popular async Kubernetes client for Python. Benchmarks against a K3s 1.35 cluster (see benchmarks/):
| Scenario | kubernetes-asyncio | kubex (aiohttp) | kubex (httpx) | Speedup |
|---|---|---|---|---|
| Single GET | 60 ms | 6 ms | 28 ms | 10x |
| List 100 pods | 2,783 ms | 74 ms | 102 ms | 37x |
| List 500 pods | 14,167 ms | 351 ms | 409 ms | 40x |
| Watch 50 events | 3,856 ms | 635 ms | 1,914 ms | 6x |
Kubex also uses 49% less heap memory and makes up to 5x fewer allocations, reducing GC pressure in long-running controllers and operators.
Fully typed
Every Kubernetes resource is a Pydantic v2 model with proper type annotations — spec fields, status fields, enums, and nested objects are all typed, not dict[str, Any]. Combined with mypy --strict support, you get IDE autocompletion and compile-time safety instead of runtime KeyErrors.
from kubex import Api, create_client
from kubex.k8s.v1_35.core.v1.pod import Pod
async with await create_client() as client:
api: Api[Pod] = Api(Pod, client=client)
pod = await api.get("my-pod", namespace="default")
# pod.spec, pod.status, pod.metadata are all fully typed
Multi-version Kubernetes support
Kubex ships separate model packages for Kubernetes 1.32 through 1.37. You can depend on exactly the versions you need, or use multiple versions simultaneously — useful when managing clusters at different upgrade stages:
from kubex.k8s.v1_34.apps.v1.deployment import Deployment as Deployment134
from kubex.k8s.v1_35.apps.v1.deployment import Deployment as Deployment135
Each package is generated from the official OpenAPI spec, so models always match the wire schema of the target cluster.
Async-runtime agnostic
Kubex works with both asyncio and trio (via httpx), with no framework lock-in.
Completed Features:
- Basic API interface that allows interaction with almost any Kubernetes resources and their methods.
- In-cluster client authorization with token refreshing.
- Basic support for kubeconfig files.
httpxandaiohttpas an underlying http-client support.asyncioandtrioasync runtime support (onlyhttpxclient is supported fortrio).- Comprehensive, fully-typed Kubernetes resource models (1.32–1.37) generated from the OpenAPI spec via a built-in code generator.
Planned Features:
- Support for OIDC and other authentication extensions.
- Fine-tuning of timeouts.
- Dynamic API object creation to exclude unsupported methods for resources (requires research for mypy compatibility).
- Potential synchronous version of the client.
- Additional tests and examples.
- JsonPatch models.
- Enhanced support for subresources (status, ephemeral containers).
- Support for Pod.attach.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kubex-0.1.0a2.tar.gz.
File metadata
- Download URL: kubex-0.1.0a2.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0687cf0f233e3538effd363731f981ac2298d850e4f1743a67d57477348d701
|
|
| MD5 |
58892cbd0c73e235157091653f9b90d9
|
|
| BLAKE2b-256 |
75c2949e2804ed1532445a0f460d9087f027cde7b494cb60c672be8387a7b1ac
|
File details
Details for the file kubex-0.1.0a2-py3-none-any.whl.
File metadata
- Download URL: kubex-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fae3966751df0cce63e203def3557ddf5de26694bdf7dcbc845eb02d16f42aed
|
|
| MD5 |
4fd7bd821aba48114bc7b242b3d960be
|
|
| BLAKE2b-256 |
1c61b69ec3ad579ca9d917fd8d5e8db71bb47aa969b25c932e0d23772107cb08
|