{"id":6055,"library":"pykube-ng","title":"Pykube-ng","description":"Pykube-ng is a lightweight Python 3.6+ client library for Kubernetes, providing a Python-native way to interact with the Kubernetes API. It's a community-maintained fork of the unmaintained `kelproject/pykube` library, focusing on simplicity and direct object interaction. The current stable version is 23.6.0, with releases occurring periodically to maintain compatibility and add features.","status":"active","version":"23.6.0","language":"en","source_language":"en","source_url":"https://github.com/msabramo/pykube-ng","tags":["kubernetes","client","k8s","cloud"],"install":[{"cmd":"pip install pykube-ng","lang":"bash","label":"Install Pykube-ng"}],"dependencies":[{"reason":"HTTP client for API communication.","package":"requests","optional":false},{"reason":"Used for JSONPath queries.","package":"jsonpath-ng","optional":true},{"reason":"Authentication for Google Cloud Kubernetes Engine.","package":"google-auth","optional":true},{"reason":"OAuth 1.0/2.0 authentication support for requests.","package":"requests-oauthlib","optional":true},{"reason":"HTTP client library, often a dependency of requests.","package":"urllib3","optional":false}],"imports":[{"symbol":"HTTPClient","correct":"from pykube import HTTPClient"},{"symbol":"KubeConfig","correct":"from pykube import KubeConfig"},{"symbol":"Deployment","correct":"from pykube import Deployment"},{"symbol":"Pod","correct":"from pykube import Pod"},{"note":"The 'all' constant for namespaces is intended for direct import from pykube.","wrong":"import pykube.all","symbol":"all","correct":"from pykube import all"}],"quickstart":{"code":"import pykube\n\n# KubeConfig.from_env() attempts to load config from in-cluster service account or ~/.kube/config\nconfig = pykube.KubeConfig.from_env()\napi = pykube.HTTPClient(config)\n\n# List all pods in all namespaces\npods = pykube.Pod.objects(api, namespace=pykube.all)\n\nprint(f\"Found {len(list(pods))} pods across all namespaces:\")\nfor pod in pods:\n    print(f\"  {pod.namespace}/{pod.name} (Status: {pod.obj['status']['phase']})\")\n\n# Get a specific deployment (replace 'my-deployment' and 'default' with actual values)\ntry:\n    deployment = pykube.Deployment.objects(api).get(name=\"my-deployment\", namespace=\"default\")\n    print(f\"\\nFound deployment: {deployment.name} in namespace {deployment.namespace}\")\nexcept pykube.exceptions.ObjectDoesNotExist:\n    print(\"\\nDeployment 'my-deployment' not found in 'default' namespace.\")","lang":"python","description":"This quickstart demonstrates how to initialize the `pykube-ng` client using environment or local kubeconfig, and then list all Kubernetes pods and retrieve a specific deployment."},"warnings":[{"fix":"Ensure your project uses Python 3.6 or newer.","message":"Python 2.7 compatibility was removed in version 0.17 when the project was forked to `pykube-ng`. Users migrating from `kelproject/pykube` must use Python 3.6+.","severity":"breaking","affected_versions":"<=0.17"},{"fix":"Always initialize `api = pykube.HTTPClient(config)` and pass `api` to object methods (e.g., `Pod.objects(api)`).","message":"The `HTTPClient` object is explicit and needs to be passed to object queries and methods. There is no implicit global configuration like in some other Kubernetes clients.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement explicit retry and reconnection logic around watch loops in your application code.","message":"Watch calls (e.g., `object.watch()`) terminate after a connection is lost (e.g., due to network issues or API server restarts). `pykube-ng` does not include internal reconnection logic or an automatic `while True` loop.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Wrap `update()` calls in a retry loop (e.g., with exponential backoff) to handle conflicts gracefully.","message":"The `APIObject.update()` method can fail if the resource was modified concurrently between being loaded and being updated, leading to a conflict. This is a common pattern in Kubernetes for optimistic concurrency.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}