Skip to main content

Kubernetes Python Pydantic Client

Reason this release was yanked:

not stable

Project description

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

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyk8s-0.0.0a1.tar.gz (68.8 kB view details)

Uploaded Source

Built Distribution

pyk8s-0.0.0a1-py3-none-any.whl (81.1 kB view details)

Uploaded Python 3

File details

Details for the file pyk8s-0.0.0a1.tar.gz.

File metadata

  • Download URL: pyk8s-0.0.0a1.tar.gz
  • Upload date:
  • Size: 68.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for pyk8s-0.0.0a1.tar.gz
Algorithm Hash digest
SHA256 1991c42778adba02a8f085da063f0939ebc000c9fb1ea396a0668b40f9928759
MD5 9c1494256da685a4c7d81b9ca767dd89
BLAKE2b-256 60438476adf514ca7caecfe6036a830c93b1955cea588ccbce46ad520b1a4b33

See more details on using hashes here.

File details

Details for the file pyk8s-0.0.0a1-py3-none-any.whl.

File metadata

  • Download URL: pyk8s-0.0.0a1-py3-none-any.whl
  • Upload date:
  • Size: 81.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for pyk8s-0.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e2ff164d9659ce562b41612ecd5bc764448ca2424524f83c6b71adb0ae25de4
MD5 2ee6d6540850f002f26f9a0211773cce
BLAKE2b-256 7a939217552b230e86bc3a5f23895058b4840574b8d9a01ec668225c2b76db67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page