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
clientmanually. - 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
- configmap:
Subresources
Subresources are available under the main resource api objects:
- example:
client.pods.exec
Work in progress
Expect breaking changes
Metadata
Release files for kubernetes-dynamic 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kubernetes-dynamic-0.1.2.tar.gz | 69.5 kB | Without provenance | Details for kubernetes-dynamic-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kubernetes_dynamic-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for kubernetes_dynamic-0.1.2-py3-none-any.whl |
Total release size: 150.8 kB
Release files / kubernetes-dynamic-0.1.2.tar.gz
| Download URL | kubernetes-dynamic-0.1.2.tar.gz |
|---|---|
| Size | 69.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0a9ffc99355f69786cfd18d7d3df2441832a5b2faf7914a0be6bf1d04564d56
|
|
BLAKE2b-256 checksum How to use checksums |
6414e1f03c15f3f29bc4900d0191ab46be77a0a1d0495ba5aab57f20bc43cdb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / kubernetes_dynamic-0.1.2-py3-none-any.whl
| Download URL | kubernetes_dynamic-0.1.2-py3-none-any.whl |
|---|---|
| Size | 81.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa2544a42cfb0f2857e87eb11c0589814a7c19fd98f59641863635888b1d1788
|
|
BLAKE2b-256 checksum How to use checksums |
5059514b965276f2987141f0a654aca87c3d207858d5d2691cc657896466d7a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for kubernetes-dynamic 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.