lightkube
Modern lightweight kubernetes module for python
NOTICE: This project is still under development and not suitable for production usage.
Highlights
- Simple interface shared across all kubernetes APIs.
- Extensive type hints to avoid common mistakes and to support autocompletion (tested on PyCharm).
- Defines models and resources generated from the swagger specifications. Models are defined using standard dataclasses.
- Lazy instantiation of inner models.
- Fast startup and small memory footprint as only needed models and resources can be loaded.
- Automatic handling of pagination when listing resources.
- Customizable handling of errors when watching resources.
This module is powered by httpx.
Installation
This module requires python >= 3.6
pip install lightkube
Usage
Read a pod
from lightkube import Client
from lightkube.resources.core_v1 import Pod
client = Client()
pod = client.get(Pod, name="my-pod", namespace="default")
print(pod.namespace.uid)
List nodes
from lightkube import Client
from lightkube.resources.core_v1 import Node
client = Client()
for node in client.list(Node):
print(node.metadata.name)
Watch deployments
from lightkube import Client
from lightkube.resources.apps_v1 import Deployment
client = Client()
for op, dep in client.watch(Deployment, namespace="default"):
print(f"{dep.namespace.name} {dep.spec.replicas}")
Create a config map
from lightkube.resources.core_v1 import ConfigMap
from lightkube.models.meta_v1 import ObjectMeta
config = ConfigMap(
metadata=ObjectMeta(name='my-config', namespace='default'),
data={'key1': 'value1', 'key2': 'value2'}
)
client.create(config)
Replace the previous config with a different content
config.data['key1'] = 'new value'
client.replace(config)
Patch an existing config
patch = {'metadata': {'labels': {'app': 'xyz'}}}
client.patch(ConfigMap, name='my-config', namespace='default', obj=patch)
Delete a namespaced resource
client.delete(ConfigMap, name='my-config', namespace='default')
Scale a deployment
from lightkube.resources.apps_v1 import Deployment
from lightkube.models.meta_v1 import ObjectMeta
from lightkube.models.autoscaling_v1 import ScaleSpec
obj = Deployment.Scale(
metadata=ObjectMeta(name='metrics-server', namespace='kube-system'),
spec=ScaleSpec(replicas=1)
)
client.replace(obj, 'metrics-server', namespace='kube-system')
Upcoming features
- Support for async/await
- Support for loading definitions from yaml files
- Support for installing a specific version of the kubernetes models
Metadata
Release files for lightkube 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lightkube-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for lightkube-0.2.1-py3-none-any.whl |
Release files / lightkube-0.2.1-py3-none-any.whl
| Download URL | lightkube-0.2.1-py3-none-any.whl |
|---|---|
| Size | 21.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
40c43bdc18292ab7562c73f691c1f4c6c22bd82f8fc6f2cd11841a8c0eb7ae6c
|
|
BLAKE2b-256 checksum How to use checksums |
9eb0f2a9cdcb858e92b08348431ebb0e5c07d95d8f2ff3cf5e5c16cafe3a2b02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3
|
Security for lightkube 0.2.1
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.