You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just experimented with Swagger v2.3.1 which supports asyncio+aiohttp based client library generation, so that we could use a "native" async interface instead of interpolating callbacks to futures.
Create symbolic links kubernetes/stream, kubernetes/config, kubernetes/watch like this repo
Create kubernetes/__init__.py like this repo
Replace all absolute imports to use relative imports (e.g., from kubernetes.api_client.apps_v1beta1_deployment import AppsV1beta1Deployment in the generated code to from .apps_v1beta1_deployment import AppsV1beta1Deployment)
Merge requirements of python-base and the generated library
pip install -e . inside a virtualenv
Fix up circular import errors related to V1beta1JSONSchemaProps
NOTE: I think find and sed commands in the generator's python.sh script should do the above changes automatically, but it didn't work out of the box. So I did manually.
Comment out ssl_verify argument in kubernetes/client/api_client.py since aiohttp forbids passing both ssl_context and ssl_verify option (the later is included in the former)
So the majority of APIs can be converted to use asyncio + aiohttp without much efforts, thanks to Swagger. I hope my "manual" fix-ups could be automated somehow!
Still, the python-base streaming wrappers should be rewritten from scratch.
At last I’ve prepared the new library kubernetes_asyncio which is based on this Python client, but uses the asyncio generator from swagger-codegen. I've added a script to create this client to kubernetes-client/gen repo in this PR kubernetes-client/gen#60. I've also decided to incorporate functionality from sub-repository kubernetes-client/python-base because a lot of changes according to asyncio were needed.
Please take a look, thanks.
Reacted by Gabi Davar, Boris Feld, Yen3, Josh Mize, Guido García, Istvan Kispal and Johan
Unlike kubernetes_asyncio, it is not backwards compatible. The user visible changes are actually minor but allowed me to remove unused Python 2.x code paths and drop Python 3.5 in favor of Python 3.7 (perhaps relevant for #558).
I added documentation and usage examples and would be grateful for any feedback - thank you.
Reacted by Tobias Bradtke, Gustavo J. A. M. Carneiro and Sergey Vasilyev
Please see #324 (comment) for discussion about experimenting asyncio library in this repo.
@olitheolix we need to be backwards compatible for this package. I haven't seen reasons for dropping Python 3.5 (and even strong needs for fully supporting 3.7) yet. What has been changed?
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
So what's the state of this? Is there a goal to merge @tomplus changes or implement a new solution?
Reacted by Denis, Sander Teunissen, Lokman Rahmani, Stephen D. Spencer, Sean Xiang, Edward Jones, Yair Bonastre, Rémi Debette, benedikt-bartscher, alexi and 1 more
I would also love to see this become a possibility, what needs to be done for this change? Would it be possible for anyone to do a wrap-up of what is needed for native asyncio support?
The attached PR seems to have gone stale and closed. People are gonna really struggle to develop WebSocket-based K8s integrations in Python without this, obviously among other use-cases.
@realabja, LOL ironically @tomplus who opened this ticket is the author of kubernetes-asyncio.
It would be much easier for everyone if such support was builtin, I'm quite sure it is a lot of work maintaining a separate version that constantly needs to catch up with the official client.
Reacted by Istvan Kispal, desiredState, Filip Brzek, Raul Ronald Galea, benedikt-bartscher, Mehrdad, wweidaa, Malte Swart, abbas jafari , alexi and 19 more
Reacted by Youngcheol Jang(장영철), desiredState, thinkpoet, Joan Prat Rigol, Rohit Krishnan, alexi, Bearnard Hibbins, Thomas Reuter, Qasim Mehmood, Dai Zhang and 3 more
Activity
tomplus commentedon Aug 19, 2017
I've prepared the Pull request where I show how callbacks can be used with asyncio. Let me know what you think about it. Thanks.
achimnol commentedon Jan 21, 2018
I just experimented with Swagger v2.3.1 which supports asyncio+aiohttp based client library generation, so that we could use a "native" async interface instead of interpolating callbacks to futures.
What I have done to make it working, starting from the kubernetes-client/gen repository:
SWAGGER_CODEGEN_COMMITinopenapi/python.shto"v2.3.1"<library>asyncio</library>underopenapi/python.xml's<configuration>element.— UPDATE: these are the "small changes" in @tomplus comment in feat: add examples for asynchronous usage (callback, asycio) #324.
kubernetespython package tokubernetes/client.kubernetes/basegit submodule.kubernetes/stream,kubernetes/config,kubernetes/watchlike this repokubernetes/__init__.pylike this repofrom kubernetes.api_client.apps_v1beta1_deployment import AppsV1beta1Deploymentin the generated code tofrom .apps_v1beta1_deployment import AppsV1beta1Deployment)pip install -e .inside a virtualenvV1beta1JSONSchemaPropsfindandsedcommands in the generator'spython.shscript should do the above changes automatically, but it didn't work out of the box. So I did manually.ssl_verifyargument inkubernetes/client/api_client.pysince aiohttp forbids passing bothssl_contextandssl_verifyoption (the later is included in the former)Then I could run the following example:
So the majority of APIs can be converted to use asyncio + aiohttp without much efforts, thanks to Swagger. I hope my "manual" fix-ups could be automated somehow!
Still, the python-base streaming wrappers should be rewritten from scratch.
seeker89 commentedon Feb 1, 2018
asyncio+aiohttpsupport would be really appreciated !EvgenyKhaliper commentedon Mar 7, 2018
I use aiohttp as a server which accesses the python-client so it will be very benefitial to me as well.
hanikesn commentedon May 18, 2018
Here's how you can do an async watch with the using client (minus error handling):
tomplus commentedon May 20, 2018
At last I’ve prepared the new library kubernetes_asyncio which is based on this Python client, but uses the asyncio generator from swagger-codegen. I've added a script to create this client to kubernetes-client/gen repo in this PR kubernetes-client/gen#60. I've also decided to incorporate functionality from sub-repository kubernetes-client/python-base because a lot of changes according to asyncio were needed.
Please take a look, thanks.
olitheolix commentedon Jul 7, 2018
Inspired by @tomplus I have followed in his footsteps and created aiokubernetes.
Unlike kubernetes_asyncio, it is not backwards compatible. The user visible changes are actually minor but allowed me to remove unused Python 2.x code paths and drop Python 3.5 in favor of Python 3.7 (perhaps relevant for #558).
I added documentation and usage examples and would be grateful for any feedback - thank you.
roycaihw commentedon Jul 27, 2018
Please see #324 (comment) for discussion about experimenting asyncio library in this repo.
@olitheolix we need to be backwards compatible for this package. I haven't seen reasons for dropping Python 3.5 (and even strong needs for fully supporting 3.7) yet. What has been changed?
fejta-bot commentedon Apr 24, 2019
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
mitar commentedon Apr 24, 2019
/remove-lifecycle stale
fejta-bot commentedon Jul 23, 2019
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
mitar commentedon Jul 23, 2019
/remove-lifecycle stale
38 remaining items
k8s-triage-robot commentedon Mar 30, 2022
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
mindw commentedon Mar 30, 2022
/remove-lifecycle stale
roycaihw commentedon Mar 30, 2022
/lifecycle frozen
takeda commentedon Dec 4, 2022
So what's the state of this? Is there a goal to merge @tomplus changes or implement a new solution?
abi-jey commentedon Mar 30, 2023
I would also love to see this become a possibility, what needs to be done for this change? Would it be possible for anyone to do a wrap-up of what is needed for native asyncio support?
remram44 commentedon Mar 30, 2023
kubernetes_asyncio works great
des1redState commentedon Sep 13, 2023
The attached PR seems to have gone stale and closed. People are gonna really struggle to develop WebSocket-based K8s integrations in Python without this, obviously among other use-cases.
abi-jey commentedon Sep 13, 2023
Why not use the dropin replacement kebernetes-asyncio? @des1redState
takeda commentedon Sep 14, 2023
@realabja, LOL ironically @tomplus who opened this ticket is the author of kubernetes-asyncio.
It would be much easier for everyone if such support was builtin, I'm quite sure it is a lot of work maintaining a separate version that constantly needs to catch up with the official client.
zeddit commentedon May 28, 2025
watching for this feature because modern python web frameworks are trending to adopt
asynciodue to the GIL.nik-paushkin commentedon Nov 30, 2025
@zeddit We've just dropped the modern async Kubernetes client - kubesdk. Check it out, hope it will help.
tamird commentedon Jul 31, 2026
I think this done now?
This series of patches brought us to the latest OpenAPI-generator shape, which has an asyncio client:
cc @yliaog
Would be great for folks here to test if this works for them.