Name | akernel JSON |
Version |
0.3.3
JSON |
| download |
home_page | None |
Summary | An asynchronous Python Jupyter kernel |
upload_time | 2025-07-10 15:44:14 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT |
keywords |
jupyter
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://github.com/davidbrochart/akernel/actions)
[](https://github.com/psf/black)
[](https://mybinder.org/v2/gh/davidbrochart/akernel/HEAD?urlpath=lab%2Ftree%2Fexamples%2Freactivity.ipynb)
# akernel
A Python Jupyter kernel, with different flavors:
- concurrent cell execution,
- reactive programming,
- cell execution caching,
- multi-kernel emulation.
## Install
```bash
pip install akernel
# pip install akernel[react] # if you want to be able to use reactive programming
# pip install akernel[cache] # if you want to be able to use cell execution caching
```
You can parameterize akernel's execution mode:
```bash
akernel install # default (chained cell execution mode)
akernel install concurrent # concurrent cell execution mode
akernel install react # reactive programming mode
akernel install cache # cell execution caching mode
akernel install multi # multi-kernel emulation mode
akernel install cache-multi-react-concurrent # you can combine several modes
```
## Motivation
[ipykernel](https://github.com/ipython/ipykernel) offers the ability to
[run asynchronous code from the REPL](https://ipython.readthedocs.io/en/stable/interactive/autoawait.html).
This means you can `await` at the top-level, outside of an async function. Unfortunately, this will still
block the kernel.
akernel changes this behavior by launching each cell in a task. By default, cell tasks are chained, which
means that a cell will start executing after the previous one is done. You might wonder, is it not the same
as ipykernel then? Well, not quite. In ipykernel, when an async cell is executing, it also blocks the
processing of
[Comm messages](https://jupyter-client.readthedocs.io/en/stable/messaging.html#custom-messages), which
prevents the kernel from interacting with e.g. JupyterLab widgets (see
[here](https://github.com/ipython/ipykernel/issues/646) and
[there](https://github.com/ipython/ipykernel/issues/696)). In akernel, it will not be the case.
If you want to go all the way and have cells execute concurrently, you can also do so (see below).
## Features
### Concurrent execution
First, set the concurrent execution mode in order to have async cells execute concurrently
(you could also do that at install-time with `akernel install concurrent`):
```python
__unchain_execution__()
# __chain_execution__()
```
akernel allows for asynchronous code execution. What this means is that when used in a Jupyter
notebook, you can run cells concurrently if the code is cooperative. For instance, you can run a
cell with the following code:
```python
# cell 1
for i in range(10):
print("cell 1:", i)
await asyncio.sleep(1)
```
Since this cell is `async` (it has an `await`), it will not block the execution of other cells.
So you can run another cell concurrently, provided that this cell is also cooperative:
```python
# cell 2
for j in range(10):
print("cell 2:", j)
await asyncio.sleep(1)
```
If cell 2 was blocking, cell 1 would pause until cell 2 was finished. You can see that by changing
`await asyncio.sleep(1)` into `time.sleep(1)` in cell 2.
You can make a cell wait for the previous one to be finished with:
```python
# cell 3
await __task__() # wait for cell 2 to be finished
print("cell 2 has run")
```
### Reactive programming
One feature other notebooks offer is the ability to have variables react to other variables'
changes. [Observable notebooks](https://observablehq.com/@observablehq/how-observable-runs) are a
good example of this, and it can give a whole new user experience. For instance, you can run cells
out of order:
```python
# cell 1
a = b + 1 # "b" is not defined yet
a
```
Executing cell 1 won't result in an "undefined variable" error. Instead, the *result* of the
operation is undefined, and the output of cell 1 is `None`. You can then continue with the
definition of `b`:
```python
# cell 2
b = 2 # triggers the computation of "a" in cell 1
```
Now `a`, which depends on `b`, is automatically updated, and the output of cell 1 is `3`.
You can of course define much more complex data flows, by defining variables on top of other ones.

### Cell execution caching
With this mode, cell execution is cached so that the next time a cell is run, its outputs are retrieved from cache (if its inputs didn't change). Inputs and outputs are inferred from the cell code.
### Multi-kernel emulation mode
This mode emulates multiple kernels inside the same kernel. Kernel isolation is achieved by using the session ID of execution requests. You can thus connect multiple notebooks to the same kernel, and they won't share execution state.
This is particularly useful if cells are async, because they won't block the kernel. The same kernel can thus be "shared" and used by potentially a lot of notebooks, greatly reducing resource usage.
## Limitations
It is still a work in progress, in particular:
- `stdout`/`stderr` redirection to the cell output is only supported through the `print` function.
- No rich representation for now, only the standard `__repr__` is supported. This means no
matplotlib figure yet :-( But since ipywidgets work, why not using
[ipympl](https://github.com/matplotlib/ipympl)? :-)
Raw data
{
"_id": null,
"home_page": null,
"name": "akernel",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "jupyter",
"author": null,
"author_email": "David Brochart <david.brochart@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c2/43/775ac3a16ae7d8cd0bbf71faf1c1d1082c52af973567c5f21c7ce247fb79/akernel-0.3.3.tar.gz",
"platform": null,
"description": "[](https://github.com/davidbrochart/akernel/actions)\n[](https://github.com/psf/black)\n[](https://mybinder.org/v2/gh/davidbrochart/akernel/HEAD?urlpath=lab%2Ftree%2Fexamples%2Freactivity.ipynb)\n\n# akernel\n\nA Python Jupyter kernel, with different flavors:\n- concurrent cell execution,\n- reactive programming,\n- cell execution caching,\n- multi-kernel emulation.\n\n## Install\n\n```bash\npip install akernel\n# pip install akernel[react] # if you want to be able to use reactive programming\n# pip install akernel[cache] # if you want to be able to use cell execution caching\n```\n\nYou can parameterize akernel's execution mode:\n\n```bash\nakernel install # default (chained cell execution mode)\nakernel install concurrent # concurrent cell execution mode\nakernel install react # reactive programming mode\nakernel install cache # cell execution caching mode\nakernel install multi # multi-kernel emulation mode\nakernel install cache-multi-react-concurrent # you can combine several modes\n```\n\n## Motivation\n\n[ipykernel](https://github.com/ipython/ipykernel) offers the ability to\n[run asynchronous code from the REPL](https://ipython.readthedocs.io/en/stable/interactive/autoawait.html).\nThis means you can `await` at the top-level, outside of an async function. Unfortunately, this will still\nblock the kernel.\n\nakernel changes this behavior by launching each cell in a task. By default, cell tasks are chained, which\nmeans that a cell will start executing after the previous one is done. You might wonder, is it not the same\nas ipykernel then? Well, not quite. In ipykernel, when an async cell is executing, it also blocks the\nprocessing of\n[Comm messages](https://jupyter-client.readthedocs.io/en/stable/messaging.html#custom-messages), which\nprevents the kernel from interacting with e.g. JupyterLab widgets (see\n[here](https://github.com/ipython/ipykernel/issues/646) and\n[there](https://github.com/ipython/ipykernel/issues/696)). In akernel, it will not be the case.\n\nIf you want to go all the way and have cells execute concurrently, you can also do so (see below).\n\n## Features\n\n### Concurrent execution\n\nFirst, set the concurrent execution mode in order to have async cells execute concurrently\n(you could also do that at install-time with `akernel install concurrent`):\n\n```python\n__unchain_execution__()\n# __chain_execution__()\n```\n\nakernel allows for asynchronous code execution. What this means is that when used in a Jupyter\nnotebook, you can run cells concurrently if the code is cooperative. For instance, you can run a\ncell with the following code:\n\n```python\n# cell 1\nfor i in range(10):\n print(\"cell 1:\", i)\n await asyncio.sleep(1)\n```\n\nSince this cell is `async` (it has an `await`), it will not block the execution of other cells.\nSo you can run another cell concurrently, provided that this cell is also cooperative:\n\n```python\n# cell 2\nfor j in range(10):\n print(\"cell 2:\", j)\n await asyncio.sleep(1)\n```\n\nIf cell 2 was blocking, cell 1 would pause until cell 2 was finished. You can see that by changing\n`await asyncio.sleep(1)` into `time.sleep(1)` in cell 2.\n\nYou can make a cell wait for the previous one to be finished with:\n\n```python\n# cell 3\nawait __task__() # wait for cell 2 to be finished\nprint(\"cell 2 has run\")\n```\n\n### Reactive programming\n\nOne feature other notebooks offer is the ability to have variables react to other variables'\nchanges. [Observable notebooks](https://observablehq.com/@observablehq/how-observable-runs) are a\ngood example of this, and it can give a whole new user experience. For instance, you can run cells\nout of order:\n\n```python\n# cell 1\na = b + 1 # \"b\" is not defined yet\na\n```\n\nExecuting cell 1 won't result in an \"undefined variable\" error. Instead, the *result* of the\noperation is undefined, and the output of cell 1 is `None`. You can then continue with the\ndefinition of `b`:\n\n```python\n# cell 2\nb = 2 # triggers the computation of \"a\" in cell 1\n```\n\nNow `a`, which depends on `b`, is automatically updated, and the output of cell 1 is `3`.\n\nYou can of course define much more complex data flows, by defining variables on top of other ones.\n\n\n\n### Cell execution caching\n\nWith this mode, cell execution is cached so that the next time a cell is run, its outputs are retrieved from cache (if its inputs didn't change). Inputs and outputs are inferred from the cell code.\n\n### Multi-kernel emulation mode\n\nThis mode emulates multiple kernels inside the same kernel. Kernel isolation is achieved by using the session ID of execution requests. You can thus connect multiple notebooks to the same kernel, and they won't share execution state.\n\nThis is particularly useful if cells are async, because they won't block the kernel. The same kernel can thus be \"shared\" and used by potentially a lot of notebooks, greatly reducing resource usage.\n\n## Limitations\n\nIt is still a work in progress, in particular:\n\n- `stdout`/`stderr` redirection to the cell output is only supported through the `print` function.\n- No rich representation for now, only the standard `__repr__` is supported. This means no\n matplotlib figure yet :-( But since ipywidgets work, why not using\n [ipympl](https://github.com/matplotlib/ipympl)? :-)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An asynchronous Python Jupyter kernel",
"version": "0.3.3",
"project_urls": {
"Homepage": "https://github.com/davidbrochart/akernel"
},
"split_keywords": [
"jupyter"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "57de74ff9270cceeb17e025582e17494bd0ee45b81aea24ff3df0f39fd85be08",
"md5": "77f0704e7dee7efeacc88d40dfd9621e",
"sha256": "9c40b14ef884a70c03839c0906372fff7b4aae3655352a7aa199af009a9498df"
},
"downloads": -1,
"filename": "akernel-0.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "77f0704e7dee7efeacc88d40dfd9621e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 20961,
"upload_time": "2025-07-10T15:44:12",
"upload_time_iso_8601": "2025-07-10T15:44:12.649210Z",
"url": "https://files.pythonhosted.org/packages/57/de/74ff9270cceeb17e025582e17494bd0ee45b81aea24ff3df0f39fd85be08/akernel-0.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c243775ac3a16ae7d8cd0bbf71faf1c1d1082c52af973567c5f21c7ce247fb79",
"md5": "50cc55d8de4bc47d6943e5b8d1f636c3",
"sha256": "5c635cf79f8973c1bb515bac044395b01d4b386a272f681e71e9e45f02e924ef"
},
"downloads": -1,
"filename": "akernel-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "50cc55d8de4bc47d6943e5b8d1f636c3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 22589,
"upload_time": "2025-07-10T15:44:14",
"upload_time_iso_8601": "2025-07-10T15:44:14.056784Z",
"url": "https://files.pythonhosted.org/packages/c2/43/775ac3a16ae7d8cd0bbf71faf1c1d1082c52af973567c5f21c7ce247fb79/akernel-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-10 15:44:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "davidbrochart",
"github_project": "akernel",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "akernel"
}