-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explicit sync and asyncio APIs (#40)
- Loading branch information
1 parent
b1331f9
commit 6cf29b2
Showing
20 changed files
with
1,710 additions
and
1,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Asyncio | ||
|
||
`kr8s` uses `asyncio` under the hood when interacting with the Kubernetes API. However, it exposes a standard synchronous API by default. | ||
|
||
```python | ||
import kr8s | ||
|
||
api = kr8s.api() | ||
pods = api.get("pods") | ||
``` | ||
|
||
For users that want it the `asyncio` API is also available via `kr8s.asyncio`. | ||
|
||
```python | ||
import kr8s.asyncio | ||
|
||
api = kr8s.asyncio.api() | ||
pods = await api.get("pods") | ||
``` | ||
|
||
Submodules including `kr8s.objects` and `kr8s.portforward` also have `asyncio` equivalents at `kr8s.asyncio.objects` and `kr8s.asyncio.portforward`. | ||
|
||
```python | ||
from kr8s.asyncio.object import Pod | ||
|
||
pod = Pod({ | ||
"apiVersion": "v1", | ||
"kind": "Pod", | ||
"metadata": { | ||
"name": "my-pod", | ||
}, | ||
"spec": { | ||
"containers": [{"name": "pause", "image": "gcr.io/google_containers/pause",}] | ||
}, | ||
}) | ||
|
||
await pod.create() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2023, Dask Developers, Yuvi Panda, Anaconda Inc, NVIDIA | ||
# SPDX-License-Identifier: BSD 3-Clause License | ||
from ._api import Api, ALL, api # noqa | ||
from functools import partial | ||
|
||
from ._api import ALL # noqa | ||
from ._api import Api as _AsyncApi | ||
from ._asyncio import sync as _sync | ||
from ._exceptions import NotFoundError # noqa | ||
from .asyncio import api as _api # noqa | ||
|
||
__version__ = "0.0.0" | ||
|
||
|
||
@_sync | ||
class Api(_AsyncApi): | ||
__doc__ = _AsyncApi.__doc__ | ||
|
||
|
||
api = partial(_api, _asyncio=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.