Skip to content

serkansahinBE/kubernetes_asyncio

 
 

Repository files navigation

Kubernetes Python Client

Build status PyPI version codecov pypi supported versions Client Capabilities Client Support Level

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: kubernetes-client/python#324

Installation

From PyPi directly:

pip install kubernetes_asyncio

Requirements: Python 3.5.3+ (required by aiohttp).

OpenAPI generator

Starting from v9.0.0 OpenAPI generator is used to generate code instead of swagger-codegen. This change should be transparent from the client point of view.

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__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    loop.close()

More complicated examples, like asynchronous multiple watch or tail logs from pods, you can find in examples/ folder.

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
python 2.7 3.4 3.5 3.6 3.7 3.8 3.5.3 3.6 3.7 3.8
streaming data via websocket from PODs bidirectional read-only is already implemented

Versions

This library is versioned in the same way as the synchronous library. The first stable version is 7.0.0 and next major versions are comparable. This compatibility table describes this library too.

Development

Install the development packages:

pip install -r requirements.txt
pip install -r test-requirements.txt

You can run the style checks and tests with

flake8 kubernetes_asyncio/
isort --diff --recursive kubernetes_asyncio/
nosetests

About

Python asynchronous client library for Kubernetes http://kubernetes.io/

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.9%
  • Shell 0.1%