Skip to main content

ImJoy RPC

Using ImJoy with Jupyter notebooks

The imjoy-rpc library enables bidirectional RPC calls between the ImJoy core and your python plugin.

The library has an abstract transport interface that can support different types of transport. For now, we support Jupyter comms message which is a custom message protocol used in Jupyter notebooks (for example powers jupyter widgets).

To use it, you need to install the imjoy-rpc library in Python and the notebook extension in javascript.

Install ImJoy RPC and Jupyter notebook extension

pip install -U imjoy-rpc imjoy-jupyter-extension

Use ImJoy plugins inside Jupyter notebooks

Now you can start a jupyter notebook via for example jupyter notebook command, you should be able to see an ImJoy icon in the toolbar if everything goes well.

imjoy in the notebook toolbar

Now run ImJoy plugins in a cell, see an example that uses itk-vtk-viewer to visualize images:

import imageio
import numpy as np
from imjoy import api

class ImJoyPlugin():
    def setup(self):
        api.log('plugin initialized')

    async def run(self, ctx):
        viewer = await api.showDialog(type="itk-vtk-viewer",
                                      src="https://oeway.github.io/itk-vtk-viewer/")
        # show a 3D volume
        image_array = np.random.randint(0, 255, [10,10,10], dtype='uint8')

        # show a 2D image
        # image_array = imageio.imread('imageio:chelsea.png')

        await viewer.imshow(image_array)

api.export(ImJoyPlugin())

With the above code, you created an ImJoy plugin. To run it, click the Run button with the ImJoy icon. It will then call the run function of your plugin.

Run Jupyter notebook inside ImJoy

You can also do the reverse by running a notebook inside ImJoy, to do that, please first create an empty jupyter notebook. Then copy and paste the url into the "+ PLUGINS" dialog, press enter and install the plugin. Click the newly installed plugin and you will get a notebook page open in ImJoy.

Try to copy and paste the itk-vtk-viewer example to a cell and execute it. Similarily, if you now click the run ImJoy button in the toolbar, you will get the viewer open insided ImJoy.

Metadata

Release files for imjoy-jupyter-extension 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imjoy-jupyter-extension 0.2.0
File Size Uploaded
imjoy-jupyter-extension-0.2.0.tar.gz 21.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for imjoy-jupyter-extension 0.2.0
File Interpreter ABI Platform
imjoy_jupyter_extension-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.3 kB

Release files / imjoy-jupyter-extension-0.2.0.tar.gz

Download URL imjoy-jupyter-extension-0.2.0.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3813b5c00b0408efc65b3d5a2cb9c2458aaad77afdafb3dd3eb03bacfed0a145
BLAKE2b-256 checksum
How to use checksums
12da775c6505a72bb982494837e66f4aeb9858c4e1913ee6d8c5efe92d8a5487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release files / imjoy_jupyter_extension-0.2.0-py3-none-any.whl

Download URL imjoy_jupyter_extension-0.2.0-py3-none-any.whl
Size 36.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a00c64bbceaf3f1c423abb52d78bcd95823e4759fcc61a9ccd7d3135d62c2ce
BLAKE2b-256 checksum
How to use checksums
2e0dfb9c4660a04465e9c154d902358c4ac34a24278bb8795162eaa4d9e7a549
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.12

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page