Skip to content

Conversation

@fleming79
Copy link

@fleming79 fleming79 commented Oct 8, 2025

This PR is a subset of #160

This PR enables asynchronous code execution as follows:

  • Python methods are coroutines (async def)
  • Each request sent to the frontend is assigned a Pending (just like an asyncio.Future). When the frontend replies, the pending is set done and the result is returned.
  • A JSON representation is returned if the result can be converted to JSON.
  • A Connection object is provided if the object returned in the frontend is a disposable (or when the transform is specified as a connection).
  • The connection can be used to:
    • access the methods and properties
    • close the object
    • use the object as a reference in the frontend using 'toObject'
    • conveted to a lumino widget using 'toLuminoWidget'

Demo running all cells at once

Awaiting in each cell ensures the result is available for the next cell. The gif below is 0.5x playback speed.

ezgif-405a2e1b8e1514bb

Menus

This gif demonstrates the usage of menus and restoration when the page is refreshed.

ezgif-4b4a42d822193ae5

Async execution is enabled in notebooks with async-kernel.

Subshells

Requires async-kernel

Leverages on the concept of kernel subshells to provide isolated user_ns and common global_user_ns.

ezgif-36277de683b32f49

resolves #11

Replaces #160

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2025

Binder 👈 Try it on Binder (branch fleming79/ipylab/ipylab-awaitable)

@fleming79

This comment was marked as outdated.

@fleming79 fleming79 force-pushed the ipylab-awaitable branch 5 times, most recently from 6e4c061 to 06d1539 Compare October 22, 2025 04:14
- All methods are async
- widget restoration on page refresh
- Preliminary support for multiple pages
- Added python classes
  - Ipylab
  - Singular
  - HasApp
  - Fixed
  - Typing instances
  - Transform
  - Connection
@fleming79 fleming79 marked this pull request as draft November 16, 2025 10:09
@fleming79
Copy link
Author

described_by was added in this commit. It provides a similar interface to the first part of #162 (printing args only).

image

This illustrates how awaitables can be used to add in more functionality.

@fleming79 fleming79 marked this pull request as ready for review November 26, 2025 03:54
@bollwyvl
Copy link
Contributor

Yeh, the goal over on #162 was to add some more optional features without breaking the public APIs (even though that took a good deal of mangling). The execute(..., handler) is likely even more interesting than describe.

Until there is a proper upstream ipywidgets async (iterable) story, I think having additive, alternate APIs here would be nice, for sure.

@fleming79
Copy link
Author

fleming79 commented Nov 26, 2025

Yeh, the goal over on #162 was to add some more optional features without breaking the public APIs (even though that took a good deal of mangling). The execute(..., handler) is likely even more interesting than describe.

Until there is a proper upstream ipywidgets async (iterable) story, I think having additive, alternate APIs here would be nice, for sure.

Your comment "Until there is a proper upstream ipywidgets async" made me realize that the patched libraries aren't required for this PR; so I've removed them. At the moment it still requires the kernel to be async-kernel, which was developed specifically to make ipylab work nicely in notebooks.

In this PR:

  • CommandRegistry.execute returns the result of execution in the frontend (or a Connection to an object).
  • The 'described_by' feature (without validation) is configurable on the CommandConnection which gets returned when a command is created.
  • Icons can be included in CommandRegistry.add_command
  • Multiple command registries are supported; a new registry can be created with CommandRegistry(name="my new registry").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for awaitables

2 participants