kubernetes-typed
raw JSON → 18.20.2 verified Fri May 01 auth: no python
Collection of mypy plugins and stubs for Kubernetes to enable strong typing of Kubernetes objects. Current version: 18.20.2. Released as needed, follows kubernetes Python client versioning.
pip install kubernetes-typed Common errors
error AttributeError: module 'kubernetes' has no attribute 'V1Deployment' ↓
cause Incorrect import path: direct 'kubernetes.V1Deployment' instead of 'kubernetes.client.models.V1Deployment'.
fix
Use: from kubernetes.client.models import V1Deployment
error Cannot find implementation or library stub for module 'kubernetes.typing' ↓
cause kubernetes-typed is not installed or not configured in mypy; mypy cannot find stubs.
fix
Install kubernetes-typed: pip install kubernetes-typed
Warnings
gotcha kubernetes-typed provides stubs for the kubernetes Python client; it does NOT replace the full kubernetes library. You must also install kubernetes. ↓
fix pip install kubernetes kubernetes-typed
breaking Version 18.20.0 introduced many changes; pin to exact minor if you encounter issues. v18.20.1 fixed a too-strict mypy version pin; v18.20.2 fixed circular imports in TypedDict definitions. ↓
fix Upgrade to 18.20.2: pip install kubernetes-typed==18.20.2
gotcha Import paths for Kubernetes models must follow the official kubernetes client paths (e.g., kubernetes.client.models.V1Deployment). Using kubernetes-typed does not change these paths. ↓
fix Use correct import: from kubernetes.client.models import V1Deployment
Imports
- V1Deployment wrong
from kubernetes import V1Deploymentcorrectfrom kubernetes.client.models import V1Deployment
Quickstart
from kubernetes import client
from kubernetes.client.models import V1Deployment
def create_deployment() -> V1Deployment:
return V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=client.V1ObjectMeta(name="example"),
spec=client.V1DeploymentSpec(
replicas=1,
selector=client.V1LabelSelector(match_labels={"app": "example"}),
template=client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "example"}),
spec=client.V1PodSpec(
containers=[client.V1Container(name="nginx", image="nginx:1.14.2")]
)
)
)
)