Kubernetes Asynchronous Python Client
Project description
Kubernetes Python Client
Asynchronous (AsyncIO) client library for the Kubernetes API.
This library is created in the same way as official https://github.com/kubernetes-client/python but uses asynchronous version of OpenAPI generator. My motivation is described here: https://github.com/kubernetes-client/python/pull/324
Installation
From PyPi directly:
pip install kubernetes_asyncio
It requires Python 3.10+
Example
To list all pods:
import asyncio
from kubernetes_asyncio import client, config
from kubernetes_asyncio.client.api_client import ApiClient
async def main():
# Configs can be set in Configuration class directly or using helper
# utility. If no argument provided, the config will be loaded from
# default location.
await config.load_kube_config()
# use the context manager to close http sessions automatically
async with ApiClient() as api:
v1 = client.CoreV1Api(api)
print("Listing pods with their IPs:")
ret = await v1.list_pod_for_all_namespaces()
for i in ret.items:
print(i.status.pod_ip, i.metadata.namespace, i.metadata.name)
if __name__ == '__main__':
asyncio.run(main())
More complicated examples, like asynchronous multiple watch or tail logs from pods,
you can find in examples/ folder.
Documentation
https://kubernetes-asyncio.readthedocs.io/
Compatibility
This library is generated in the same way as the official Kubernetes Python Library. It uses swagger-codegen and the same concepts like streaming, watching or reading configuration. Because of an early stage of this library some differences still exist:
| synchronous library kubernetes-client/python | this library | |
|---|---|---|
| authentication method | gcp-token, azure-token, user-token, oidc-token, user-password, in-cluster | gcp-token (only via gcloud command), user-token, oidc-token, user-password, in-cluster |
| streaming data via websocket from PODs | bidirectional | read-only is already implemented |
Microsoft Windows
In case this library is used against Kubernetes cluster using client-go credentials plugin, the default asyncio event loop is SelectorEventLoop. This event loop selector, however, does NOT support pipes and subprocesses, so exec_provider.py::ExecProvider is failing. In order to avoid failures the ProactorEventLoop has to be selected. The ProactorEventLoop can be enabled via WindowsProactorEventLoopPolicy.
Application's code needs to contain following code:
import asyncio
asyncio.set_event_loop_policy(
asyncio.WindowsProactorEventLoopPolicy()
)
Versions
This library is versioned in the same way as the synchronous library. The schema version has been changed with version v18.20.0. Now, first two numbers from version are Kubernetes version (v.1.18.20). The last number is for changes in the library not directly connected with K8s.
Development
# Create and activate virtual environment
uv venv
source .venv/bin/activate
# Install dependencies
uv sync
# Run ruff
ruff check .
ruff format --diff .
# Run tests
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kubernetes_asyncio-35.0.0.tar.gz.
File metadata
- Download URL: kubernetes_asyncio-35.0.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9921d93838fae33993d5b563c7a5e591e9934826e5dcd6556d4adcf9fa600b40
|
|
| MD5 |
251009278d304f14621005baedf54689
|
|
| BLAKE2b-256 |
306415fe503534746573252dee4a5d7714b24d1b4a536fcf6a84bc522e175cef
|
Provenance
The following attestation bundles were made for kubernetes_asyncio-35.0.0.tar.gz:
Publisher:
publish.yaml on tomplus/kubernetes_asyncio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kubernetes_asyncio-35.0.0.tar.gz -
Subject digest:
9921d93838fae33993d5b563c7a5e591e9934826e5dcd6556d4adcf9fa600b40 - Sigstore transparency entry: 950197337
- Sigstore integration time:
-
Permalink:
tomplus/kubernetes_asyncio@c68e69ce07143b8f53897e728e2c3dc6fc912fbe -
Branch / Tag:
refs/tags/35.0.0 - Owner: https://github.com/tomplus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@c68e69ce07143b8f53897e728e2c3dc6fc912fbe -
Trigger Event:
push
-
Statement type:
File details
Details for the file kubernetes_asyncio-35.0.0-py3-none-any.whl.
File metadata
- Download URL: kubernetes_asyncio-35.0.0-py3-none-any.whl
- Upload date:
- Size: 2.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cea90dfc93f63a79314c164f3d6e0fb3f1fa41e6fa2fb7ab472f95c1eead97eb
|
|
| MD5 |
17eb3b0b090cb4c02dd8b019de94d94a
|
|
| BLAKE2b-256 |
33d59816fc74aaa873b1138877835722250f6575e8cf5d4c13fd66c96aab5da5
|
Provenance
The following attestation bundles were made for kubernetes_asyncio-35.0.0-py3-none-any.whl:
Publisher:
publish.yaml on tomplus/kubernetes_asyncio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kubernetes_asyncio-35.0.0-py3-none-any.whl -
Subject digest:
cea90dfc93f63a79314c164f3d6e0fb3f1fa41e6fa2fb7ab472f95c1eead97eb - Sigstore transparency entry: 950197392
- Sigstore integration time:
-
Permalink:
tomplus/kubernetes_asyncio@c68e69ce07143b8f53897e728e2c3dc6fc912fbe -
Branch / Tag:
refs/tags/35.0.0 - Owner: https://github.com/tomplus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@c68e69ce07143b8f53897e728e2c3dc6fc912fbe -
Trigger Event:
push
-
Statement type: