kubernetes-dynamic


Namekubernetes-dynamic JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryKubernetes Dynamic client
upload_time2023-04-11 15:51:09
maintainer
docs_urlNone
author
requires_python>=3.7
licenseBSD-3-Clause
keywords kubernetes client kubernetes-client kubernetes-dynamic dynamic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # kubernetes-dynamic

This project aims to provide an easy interface over kubernetes API based on the official kubernetes package.

Basic syntax is very similar to kubectl.

`client.pods.get()` is the same as `kubectl get pods`

## Example Usage

```python
import kubernetes_dynamic as kd

client = kd.K8sClient()
pods: list[kd.models.V1Pod] = client.pods.get()
for pod in pods:
    print(pod.metadata.name)
```

### Custom resources

```python
import kubernetes_dynamic as kd

class MyModel(kd.models.ResourceItem):
    field: str


api: ResourceApi[MyModel] = kc.cl.get_api("mycustomresources", MyModel)
api: ResourceApi[MyModel] = kc.cl.get_api(kind="MyCustomResource", object_type=MyModel)
items: List[MyModel] = api.get()
item: Optional[MyModel] = api.get(name="exact-name")
if item:
    item.field = "modified"
    item.patch()
else:
    item = MyModel(metadata={"name": "exact-name", "namespace": "namespace-name"}, field="created", client=kd.cl)
    item.create()
    # item = MyModel(field="created")
    # item.metadata.name = "exact-name"

    # item = MyModel(metadata={"name": "exact-name"}, field="created")

    # item = MyModel(metadata=kd.models.V1Metadata(name="exact-name"), field="created")
    # item.create(namespace="namespace-name")
```

## Models

We aim to provide pydantic models for all reasources.

Because the model names are exactly the same as in the `kubernetes` package, make sure you import the models from `kubernetes_dynamic.models`

- Proper type hinting
- All models are flexible (less dependent on kubernetes version):
  - accept extra values
  - all optional (type checker is tricked into assuming everything exists)
- Models created by queries have a reference to the client it was created by, manually creating models creates a default client(without arguments), or you can specify `client` manually.
- Base model contains common methods for all models:
  - refresh
  - patch
  - create
  - read
  - delete
  - is_ready
- additional features for specific models (just examples):
  - configmap:
    - from_path
  - ingress:
    - get_default_host
  - namespace:
    - annotate
    - ensure
  - pod:
    - get_restarts
    - exec
    - disk_usage
    - get_controller_type
    - get_env
  - secret
    - exists
    - set
    - decode

## Subresources

Subresources are available under the main resource api objects:

- example: `client.pods.exec`

## Work in progress

Expect breaking changes

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "kubernetes-dynamic",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "kubernetes,client,kubernetes-client,kubernetes-dynamic,dynamic",
    "author": "",
    "author_email": "Attila Kobor <atti92@gmail.com>, Balazs Hamorszky <balihb@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/64/14/e1f03c15f3f29bc4900d0191ab46be77a0a1d0495ba5aab57f20bc43cdb9/kubernetes-dynamic-0.1.2.tar.gz",
    "platform": null,
    "description": "# kubernetes-dynamic\n\nThis project aims to provide an easy interface over kubernetes API based on the official kubernetes package.\n\nBasic syntax is very similar to kubectl.\n\n`client.pods.get()` is the same as `kubectl get pods`\n\n## Example Usage\n\n```python\nimport kubernetes_dynamic as kd\n\nclient = kd.K8sClient()\npods: list[kd.models.V1Pod] = client.pods.get()\nfor pod in pods:\n    print(pod.metadata.name)\n```\n\n### Custom resources\n\n```python\nimport kubernetes_dynamic as kd\n\nclass MyModel(kd.models.ResourceItem):\n    field: str\n\n\napi: ResourceApi[MyModel] = kc.cl.get_api(\"mycustomresources\", MyModel)\napi: ResourceApi[MyModel] = kc.cl.get_api(kind=\"MyCustomResource\", object_type=MyModel)\nitems: List[MyModel] = api.get()\nitem: Optional[MyModel] = api.get(name=\"exact-name\")\nif item:\n    item.field = \"modified\"\n    item.patch()\nelse:\n    item = MyModel(metadata={\"name\": \"exact-name\", \"namespace\": \"namespace-name\"}, field=\"created\", client=kd.cl)\n    item.create()\n    # item = MyModel(field=\"created\")\n    # item.metadata.name = \"exact-name\"\n\n    # item = MyModel(metadata={\"name\": \"exact-name\"}, field=\"created\")\n\n    # item = MyModel(metadata=kd.models.V1Metadata(name=\"exact-name\"), field=\"created\")\n    # item.create(namespace=\"namespace-name\")\n```\n\n## Models\n\nWe aim to provide pydantic models for all reasources.\n\nBecause the model names are exactly the same as in the `kubernetes` package, make sure you import the models from `kubernetes_dynamic.models`\n\n- Proper type hinting\n- All models are flexible (less dependent on kubernetes version):\n  - accept extra values\n  - all optional (type checker is tricked into assuming everything exists)\n- Models created by queries have a reference to the client it was created by, manually creating models creates a default client(without arguments), or you can specify `client` manually.\n- Base model contains common methods for all models:\n  - refresh\n  - patch\n  - create\n  - read\n  - delete\n  - is_ready\n- additional features for specific models (just examples):\n  - configmap:\n    - from_path\n  - ingress:\n    - get_default_host\n  - namespace:\n    - annotate\n    - ensure\n  - pod:\n    - get_restarts\n    - exec\n    - disk_usage\n    - get_controller_type\n    - get_env\n  - secret\n    - exists\n    - set\n    - decode\n\n## Subresources\n\nSubresources are available under the main resource api objects:\n\n- example: `client.pods.exec`\n\n## Work in progress\n\nExpect breaking changes\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Kubernetes Dynamic client",
    "version": "0.1.2",
    "split_keywords": [
        "kubernetes",
        "client",
        "kubernetes-client",
        "kubernetes-dynamic",
        "dynamic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5059514b965276f2987141f0a654aca87c3d207858d5d2691cc657896466d7a2",
                "md5": "0aec792d153b371766618283dde133cb",
                "sha256": "aa2544a42cfb0f2857e87eb11c0589814a7c19fd98f59641863635888b1d1788"
            },
            "downloads": -1,
            "filename": "kubernetes_dynamic-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0aec792d153b371766618283dde133cb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 81329,
            "upload_time": "2023-04-11T15:51:07",
            "upload_time_iso_8601": "2023-04-11T15:51:07.403076Z",
            "url": "https://files.pythonhosted.org/packages/50/59/514b965276f2987141f0a654aca87c3d207858d5d2691cc657896466d7a2/kubernetes_dynamic-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6414e1f03c15f3f29bc4900d0191ab46be77a0a1d0495ba5aab57f20bc43cdb9",
                "md5": "7114c6332785d4752a6f7955e51e6aea",
                "sha256": "a0a9ffc99355f69786cfd18d7d3df2441832a5b2faf7914a0be6bf1d04564d56"
            },
            "downloads": -1,
            "filename": "kubernetes-dynamic-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "7114c6332785d4752a6f7955e51e6aea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 69477,
            "upload_time": "2023-04-11T15:51:09",
            "upload_time_iso_8601": "2023-04-11T15:51:09.255038Z",
            "url": "https://files.pythonhosted.org/packages/64/14/e1f03c15f3f29bc4900d0191ab46be77a0a1d0495ba5aab57f20bc43cdb9/kubernetes-dynamic-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-11 15:51:09",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "kubernetes-dynamic"
}
        
Elapsed time: 0.07013s