kubernetes-typed


Namekubernetes-typed JSON
Version 18.20.2 PyPI version JSON
download
home_pagehttps://github.com/gordonbondon/kubernetes-typed
SummaryCollection of mypy plugins and stubs for kubernetes
upload_time2024-09-02 19:06:17
maintainerNone
docs_urlNone
authorArtem Yarmoliuk
requires_python>=3.8
licenseApache License Version 2.0
keywords kubernetes mypy stubs typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="http://mypy-lang.org/static/mypy_light.svg" alt="mypy logo" width="300px"/>

# kubernetes-typed

[![Build status](https://github.com/gordonbondon/kubernetes-typed/workflows/Test/badge.svg?branch=master&event=push)](https://github.com/gordonbondon/kubernetes-typed/actions?query=workflow%3ATest+branch%3Amaster)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)

mypy plugin to dynamically define types for Kubernetes objects.

## Features

* [Type checking for Custom Resources](#Custom-Resource-Definitions)
* [Type checking for kubernetes-client](#Kubernetes-Python-Client-types)

## Installation

Install with `pip`:
```shell
pip install kubernetes-typed
```

### Versioning

This package follows `kubernetes` client [versioning approach](https://github.com/kubernetes-client/python#homogenizing-the-kubernetes-python-client-versions).
`MAJOR.MINOR` parts of version will match client version for which stubs were generated, and `PATCH` version will be stub or plugin specific updates.

## Custom Resource Definitions

Add 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 .

1. Configure `mypy` to use `crd_typed` plugin:
```ini
[mypy]

plugins = crd_typed.plugin
```

2. Import `CustomResource`

```python
from crd_type import CustomResource
```

3. [Annotate](https://mypy.readthedocs.io/en/stable/type_inference_and_annotations.html#explicit-types-for-variables) your variables:

```python
resource: CustomResource["relative/path/to/crd.yaml"]
```

You can get type definition for different parts of crd:

* Get `TypeDict` definition for custom resource body:

    ```python
    from crd_type import CustomResource

    resource: CustomResource["relative/path/to/crd.yaml"]
    ```

* Get definition only for resource `spec`:

    ```python
    from crd_type import CustomResource

    resource: CustomResource["relative/path/to/crd.yaml", "spec"]
    ```

* Get definition for nested spec item, if that item is type `object` or `array`:

    ```python
    from crd_type import CustomResource

    resource: CustomResource["relative/path/to/crd.yaml", "spec", "some_property"]
    ```

* Get definition for array item, if that is array of objects, via `items` key:

    ```python
    from crd_type import CustomResource

    resource: CustomResource["relative/path/to/crd.yaml", "spec", "some_array_of_objects", "items"]
    ```

### Limitations

* CRDs that use `additionalProperties` are not supported.
* CRDs can define multiple `versions`, currently only first one will be used
* Custom attributes like `x-kubernetes-int-or-string`, `x-kubernetes-embedded-resource`, are not supported

## Kubernetes Python Client types

This 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.

To enable full type checking for classes use provided `kubernetes_typed` plugin. This plugin requires `kubernetes`, you can require it during installation like this:

```shell
pip install kubernetes-typed[client]
```

Configure `mypy` to use it and it will automatically type check classes from `kubernetes.client`:

```ini
[mypy]

plugins = kubernetes_typed.plugin
```

### Kubernetes Python Client Models Dict Types

If you want to type check resource dicts instead of classes, you can use generated `TypedDict`s provided by this package.

To do this for any model class in `kubernetes.client` append its name with `Dict`, and import it from `kubernetes_type.client`

For example:

`kubernetes.client.V1Pod` -> `kubernetes_typed.client.V1PodDict`

```python
from kubernetes.client.api import core_v1_api

from kubernetes_typed.client import V1PodDict

api_instance = core_v1_api.CoreV1Api()

pod_manifest: V1PodDict = {
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {"name": "test-pod"},
    "spec": {
        "containers": [
            {
                "image": "nginx",
                "name": "nginx",
            },
        ],
    },
}

api_instance.create_namespaced_pod(body=pod_manifest, namespace='default')
```

### Limitations

* 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gordonbondon/kubernetes-typed",
    "name": "kubernetes-typed",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "Kubernetes, MyPy, Stubs, Typing",
    "author": "Artem Yarmoliuk",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/37/4c/0f49075f2ca5f4bd2c5ec05f0ca37c1649076a3bd93ae13f593f95fb31ba/kubernetes_typed-18.20.2.tar.gz",
    "platform": null,
    "description": "<img src=\"http://mypy-lang.org/static/mypy_light.svg\" alt=\"mypy logo\" width=\"300px\"/>\n\n# kubernetes-typed\n\n[![Build status](https://github.com/gordonbondon/kubernetes-typed/workflows/Test/badge.svg?branch=master&event=push)](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` -> `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",
    "bugtrack_url": null,
    "license": "Apache License Version 2.0",
    "summary": "Collection of mypy plugins and stubs for kubernetes",
    "version": "18.20.2",
    "project_urls": {
        "Bug Reports": "https://github.com/gordonbondon/kubernetes-typed/issues",
        "Homepage": "https://github.com/gordonbondon/kubernetes-typed",
        "Source": "https://github.com/gordonbondon/kubernetes-typed"
    },
    "split_keywords": [
        "kubernetes",
        " mypy",
        " stubs",
        " typing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dad5d13cf0211d950b19b89683e65829b4da9c8b2eed0b71afec564f240e3bcb",
                "md5": "f96cb54593bdb9ee6be27043740cda40",
                "sha256": "dff59feb21c092a83ac5b0e65b9cc5f9d00caa95833e0c486692dedfc1276a13"
            },
            "downloads": -1,
            "filename": "kubernetes_typed-18.20.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f96cb54593bdb9ee6be27043740cda40",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 757856,
            "upload_time": "2024-09-02T19:06:16",
            "upload_time_iso_8601": "2024-09-02T19:06:16.201682Z",
            "url": "https://files.pythonhosted.org/packages/da/d5/d13cf0211d950b19b89683e65829b4da9c8b2eed0b71afec564f240e3bcb/kubernetes_typed-18.20.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "374c0f49075f2ca5f4bd2c5ec05f0ca37c1649076a3bd93ae13f593f95fb31ba",
                "md5": "becc6af78c6d76944dfb5e453ddb623a",
                "sha256": "5c2fcf5de2b3192133a4cba9d0d8f7187e4ccc7f7ad6d3a17dfe67ea5b90b101"
            },
            "downloads": -1,
            "filename": "kubernetes_typed-18.20.2.tar.gz",
            "has_sig": false,
            "md5_digest": "becc6af78c6d76944dfb5e453ddb623a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 199120,
            "upload_time": "2024-09-02T19:06:17",
            "upload_time_iso_8601": "2024-09-02T19:06:17.737145Z",
            "url": "https://files.pythonhosted.org/packages/37/4c/0f49075f2ca5f4bd2c5ec05f0ca37c1649076a3bd93ae13f593f95fb31ba/kubernetes_typed-18.20.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-02 19:06:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gordonbondon",
    "github_project": "kubernetes-typed",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "kubernetes-typed"
}
        
Elapsed time: 0.30929s