Skip to main content

An asynchronous Python Jupyter kernel

Project description

Build Status Code style: black

akernel

An asynchronous Python Jupyter kernel, with optional reactive programming.

Install

pip install akernel

If you want to be able to use reactive programming:

pip install akernel[react]

Note that it will just add ipyx, which you could also install later if you want (pip install ipyx).

You can switch between reactive and non-reactive modes by entering:

akernel install react  # enable reactive mode
akernel install async  # disable reactive mode

Motivation

ipykernel offers the ability to run asynchronous code from the REPL. This means you can await at the top-level, outside of a function. Unfortunately, this will still block the kernel.

akernel changes this behavior by launching each cell in a task.

Features

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:

# 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:

# 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:

# cell 3
await __task__()  # wait for cell 2 to be finished
print("cell 2 has run")

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 ipywidgets should work!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

akernel-0.0.10.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

akernel-0.0.10-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file akernel-0.0.10.tar.gz.

File metadata

  • Download URL: akernel-0.0.10.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for akernel-0.0.10.tar.gz
Algorithm Hash digest
SHA256 4573395f1b0f75780aae645f91f5d86e4c4e7705ae47c1393a80e0146aaa61e8
MD5 c8d7c154b48571843b5101ab50c07ff1
BLAKE2b-256 6013fdd3a112a3c795e635d99445a3b0cf3bec041f937dab5c4b66aca2c22a63

See more details on using hashes here.

File details

Details for the file akernel-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: akernel-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for akernel-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b5d3a9815c46ce21bdb7231a46f989d180b36c83b5ae8e8bb0acb51c7b92e0f0
MD5 cef4b03490c7eb64e0926b7678b638eb
BLAKE2b-256 9725b6a81526cd199d86ed9854bab75d5b7811cb2096f3250949e1c2fbd1e114

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page