▲ 1 r/kubernetes
Hi everyone. Today I released the first beta of an async Kubernetes client for Python inspired by kube.rs. Why I decided to build it:
- got tired of writing
# type: ignoreevery time I used kubernetes-asyncio - got tired of endlessly digging around to figure out what shape kubernetes-asyncio expects for a given piece of a resource spec
- limited built-in support for working with custom resources, which is critical when writing controllers
What's there now:
- Strictly typed API and resource models
- Support for multiple Kubernetes versions simultaneously
- Typed models covering the entire Kubernetes spec
- Full custom resource support — just write a Pydantic model for the resource you need, and you can work with it the same way you'd work with a built-in
aiohttpandhttpxas the underlying HTTP clients- Support for
asyncioandtrio - Thanks to Pydantic v2, Kubex is dramatically faster than kubernetes-asyncio, uses much less memory, and makes fewer heap allocations (see benchmarks)
Links:
Docs: https://kubex.codemageddon.me/0.1.0-beta.1/
GitHub: https://github.com/codemageddon/kubex
Code example:
from kubex.api import Api
from kubex.client import create_client
from kubex.k8s.v1_35.core.v1.pod import Pod
async with await create_client() as client:
pod_api: Api[Pod] = Api(Pod, client=client, namespace="default")
pods = await pod_api.list()
for pod in pods.items:
print(pod.metadata.name, pod.status.phase)
---
The library is currently in early beta, meaning the public API surface may still change — but it's unlikely to change much, at least for the core functionality.
u/Codemageddon — 10 days ago