Registry / type-stubs / kubernetes-stubs

kubernetes-stubs

JSON →
library22.6.0.post1pypypi✓ verified 24d ago

Type stubs for the Kubernetes Python API client. This library provides static type checking for code interacting with the `kubernetes` client library. The version numbers of `kubernetes-stubs` generally track the upstream `kubernetes` client library. As of version 22.6.0.post1, it provides type definitions mirroring the API of the corresponding Kubernetes client version. Contributions and bug fixes are welcomed.

pip install kubernetes-stubs
INSTALL
IMPORT
SIG · KUBERNETES-STUBS
K
kubernetes-stubs
type-stubspythonv22.6.0.post1
Install
1.9s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v22.6.0.post1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.000s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

client
from kubernetes_stubs import client
from kubernetes_ext import client

This quickstart demonstrates how to initialize the Kubernetes Python client and list all pods across all namespaces, benefiting from the type stubs for static analysis. It attempts to load configuration from a kubeconfig file (respecting KUBECONFIG environment variable) or falls back to in-cluster configuration.

import os from kubernetes import client, config try: # Try to load kubeconfig from default location (e.g., ~/.kube/config) config.load_kube_config(config_file=os.environ.get('KUBECONFIG')) except config.config_exception.ConfigException: # Fallback to in-cluster config if KUBECONFIG is not set or file not found config.load_incluster_config() v1 = client.CoreV1Api() print("Listing pods with their IPs:") ret = v1.list_pod_for_all_namespaces(watch=False) for i in ret.items: print(f"{i.status.pod_ip}\t{i.metadata.namespace}\t{i.metadata.name}")
Debug
Known issues
gotchaThe `kubernetes-stubs` library can sometimes lag behind new releases of the official `kubernetes` client library, leading to missing type definitions for the latest API versions or newly added fields. Consider using forks like `kubernetes-stubs-elephant-fork` if you need more up-to-date stubs.
fix
Check the project's GitHub for latest releases or explore community-maintained forks like `kubernetes-stubs-elephant-fork` for newer Kubernetes client versions.
affects: <=22.6.0.post1
gotchaThe generated stubs may not always be complete or entirely accurate for all edge cases or dynamically generated Kubernetes resources (like Custom Resource Definitions). For more comprehensive type checking for CRDs or client API functions, consider using `kubernetes-typed` with its `mypy` plugin.
fix
For advanced type-checking needs, especially with Custom Resources, investigate `kubernetes-typed` and its `mypy` plugin for enhanced capabilities.
affects: All
gotchaThe underlying Kubernetes API frequently deprecates older API versions and fields. While `kubernetes-stubs` tracks the Python client, using deprecated APIs in your code can still lead to runtime warnings or failures in a Kubernetes cluster, even if the stubs permit them. Always refer to the official Kubernetes API documentation for deprecation policies.
fix
Regularly consult the official Kubernetes API documentation for deprecation notices and update your code to use current API versions and fields.
affects: All
Upgrade
Version history
22.6.0.post1latest on PyPI · released Apr 20, 2022
Audit
Dependencies
kubernetesrequiredProvides the runtime Kubernetes Python client API that these stubs type-check.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
kubernetes-stubs — pip install kubernetes-stubs · libregistry