{"id":13800981,"url":"https://github.com/gordonbondon/kubernetes-typed","last_synced_at":"2025-03-17T04:09:41.128Z","repository":{"id":47272480,"uuid":"319183135","full_name":"gordonbondon/kubernetes-typed","owner":"gordonbondon","description":"mypy plugin to type check Kubernetes resources","archived":false,"fork":false,"pushed_at":"2024-09-08T12:17:03.000Z","size":589,"stargazers_count":23,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-11T10:18:45.842Z","etag":null,"topics":["crd","kubernetes","kubernetes-development","kubernetes-python-client","mypy","mypy-plugins","mypy-stubs","pep484","python-types"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/kubernetes-typed/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gordonbondon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-07T02:34:12.000Z","updated_at":"2025-03-05T14:00:04.000Z","dependencies_parsed_at":"2024-09-08T13:36:11.968Z","dependency_job_id":"7f38cbda-4eba-4548-840e-1e45001ab8e0","html_url":"https://github.com/gordonbondon/kubernetes-typed","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.03703703703703709,"last_synced_commit":"17e6a2610594f9f48eeeb105b2ebe4c1877fd777"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordonbondon%2Fkubernetes-typed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordonbondon%2Fkubernetes-typed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordonbondon%2Fkubernetes-typed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordonbondon%2Fkubernetes-typed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gordonbondon","download_url":"https://codeload.github.com/gordonbondon/kubernetes-typed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243971190,"owners_count":20376784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crd","kubernetes","kubernetes-development","kubernetes-python-client","mypy","mypy-plugins","mypy-stubs","pep484","python-types"],"created_at":"2024-08-04T00:01:18.226Z","updated_at":"2025-03-17T04:09:41.107Z","avatar_url":"https://github.com/gordonbondon.png","language":"Python","funding_links":[],"categories":["Tools"],"sub_categories":["Mypy plugins"],"readme":"\u003cimg src=\"http://mypy-lang.org/static/mypy_light.svg\" alt=\"mypy logo\" width=\"300px\"/\u003e\n\n# kubernetes-typed\n\n[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)\n[![Build status](https://github.com/gordonbondon/kubernetes-typed/actions/workflows/pull_request.yml/badge.svg?branch=master)](https://github.com/gordonbondon/kubernetes-typed/actions?query=workflow%3ATest+branch%3Amaster)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\nmypy plugin to dynamically define types for Kubernetes objects.\n\n## Features\n\n* [Type checking for Custom Resources](#Custom-Resource-Definitions)\n* [Type checking for kubernetes-client](#Kubernetes-Python-Client-types)\n\n## Installation\n\nInstall with `pip`:\n```shell\npip install kubernetes-typed\n```\n\n### Versioning\n\nThis package follows `kubernetes` client [versioning approach](https://github.com/kubernetes-client/python#homogenizing-the-kubernetes-python-client-versions).\n`MAJOR.MINOR` parts of version will match client version for which stubs were generated, and `PATCH` version will be stub or plugin specific updates.\n\n## Custom Resource Definitions\n\nAdd type checks for [Custom Resource Definition](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/) spec given its definition in `yaml` file .\n\n1. Configure `mypy` to use `crd_typed` plugin:\n```ini\n[mypy]\n\nplugins = crd_typed.plugin\n```\n\n2. Import `CustomResource`\n\n```python\nfrom crd_type import CustomResource\n```\n\n3. [Annotate](https://mypy.readthedocs.io/en/stable/type_inference_and_annotations.html#explicit-types-for-variables) your variables:\n\n```python\nresource: CustomResource[\"relative/path/to/crd.yaml\"]\n```\n\nYou can get type definition for different parts of crd:\n\n* Get `TypeDict` definition for custom resource body:\n\n    ```python\n    from crd_type import CustomResource\n\n    resource: CustomResource[\"relative/path/to/crd.yaml\"]\n    ```\n\n* Get definition only for resource `spec`:\n\n    ```python\n    from crd_type import CustomResource\n\n    resource: CustomResource[\"relative/path/to/crd.yaml\", \"spec\"]\n    ```\n\n* Get definition for nested spec item, if that item is type `object` or `array`:\n\n    ```python\n    from crd_type import CustomResource\n\n    resource: CustomResource[\"relative/path/to/crd.yaml\", \"spec\", \"some_property\"]\n    ```\n\n* Get definition for array item, if that is array of objects, via `items` key:\n\n    ```python\n    from crd_type import CustomResource\n\n    resource: CustomResource[\"relative/path/to/crd.yaml\", \"spec\", \"some_array_of_objects\", \"items\"]\n    ```\n\n### Limitations\n\n* CRDs that use `additionalProperties` are not supported.\n* CRDs can define multiple `versions`, currently only first one will be used\n* Custom attributes like `x-kubernetes-int-or-string`, `x-kubernetes-embedded-resource`, are not supported\n\n## Kubernetes Python Client types\n\nThis package provides basic [type stubs](https://www.python.org/dev/peps/pep-0561/) for [kubernetes python client](https://github.com/kubernetes-client/python) out of the box.\n\nTo enable full type checking for classes use provided `kubernetes_typed` plugin. This plugin requires `kubernetes`, you can require it during installation like this:\n\n```shell\npip install kubernetes-typed[client]\n```\n\nConfigure `mypy` to use it and it will automatically type check classes from `kubernetes.client`:\n\n```ini\n[mypy]\n\nplugins = kubernetes_typed.plugin\n```\n\n### Kubernetes Python Client Models Dict Types\n\nIf you want to type check resource dicts instead of classes, you can use generated `TypedDict`s provided by this package.\n\nTo do this for any model class in `kubernetes.client` append its name with `Dict`, and import it from `kubernetes_type.client`\n\nFor example:\n\n`kubernetes.client.V1Pod` -\u003e `kubernetes_typed.client.V1PodDict`\n\n```python\nfrom kubernetes.client.api import core_v1_api\n\nfrom kubernetes_typed.client import V1PodDict\n\napi_instance = core_v1_api.CoreV1Api()\n\npod_manifest: V1PodDict = {\n    \"apiVersion\": \"v1\",\n    \"kind\": \"Pod\",\n    \"metadata\": {\"name\": \"test-pod\"},\n    \"spec\": {\n        \"containers\": [\n            {\n                \"image\": \"nginx\",\n                \"name\": \"nginx\",\n            },\n        ],\n    },\n}\n\napi_instance.create_namespaced_pod(body=pod_manifest, namespace='default')\n```\n\n### Limitations\n\n* Kubernetes client api functions are currently not covered by stubs, so you might get `Call to untyped function` errors. Check [mypy config doc](https://mypy.readthedocs.io/en/stable/config_file.html) on how to disable separate warnings.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgordonbondon%2Fkubernetes-typed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgordonbondon%2Fkubernetes-typed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgordonbondon%2Fkubernetes-typed/lists"}