ipykernel.comm package#

Submodules#

Base class for a Comm

class ipykernel.comm.comm.Comm(**kwargs: Any)#

Bases: LoggingConfigurable

Class for communicating between a Frontend and a Kernel

close(data=None, metadata=None, buffers=None, deleting=False)#

Close the frontend-side version of this comm

comm_id#

A trait for unicode strings.

handle_close(msg)#

Handle a comm_close message

handle_msg(msg)#

Handle a comm_msg message

kernel#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

on_close(callback)#

Register a callback for comm_close

Will be called with the data of the close message.

Call on_close(None) to disable an existing callback.

on_msg(callback)#

Register a callback for comm_msg

Will be called with the data of any comm_msg messages.

Call on_msg(None) to disable an existing callback.

open(data=None, metadata=None, buffers=None)#

Open the frontend-side version of this comm

primary#

Am I the primary or secondary Comm?

send(data=None, metadata=None, buffers=None)#

Send a message to the frontend-side version of this comm

target_module#

requirejs module from which to load comm target.

target_name#

A trait for unicode strings.

topic#

A trait for byte strings.

Base class to manage comms

class ipykernel.comm.manager.CommManager(**kwargs: Any)#

Bases: LoggingConfigurable

Manager for Comms in the Kernel

comm_close(stream, ident, msg)#

Handler for comm_close messages

comm_msg(stream, ident, msg)#

Handler for comm_msg messages

comm_open(stream, ident, msg)#

Handler for comm_open messages

comms#

An instance of a Python dict.

One or more traits can be passed to the constructor to validate the keys and/or values of the dict. If you need more detailed validation, you may use a custom validator method.

Changed in version 5.0: Added key_trait for validating dict keys.

Changed in version 5.0: Deprecated ambiguous trait, traits args in favor of value_trait, per_key_traits.

get_comm(comm_id)#

Get a comm with a particular id

Returns the comm if found, otherwise None.

This will not raise an error, it will log messages if the comm cannot be found.

kernel#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

register_comm(comm)#

Register a new comm

register_target(target_name, f)#

Register a callable f for a given target name

f will be called with two arguments when a comm_open message is received with target:

  • the Comm instance

  • the comm_open message itself.

f can be a Python callable or an import string for one.

targets#

An instance of a Python dict.

One or more traits can be passed to the constructor to validate the keys and/or values of the dict. If you need more detailed validation, you may use a custom validator method.

Changed in version 5.0: Added key_trait for validating dict keys.

Changed in version 5.0: Deprecated ambiguous trait, traits args in favor of value_trait, per_key_traits.

unregister_comm(comm)#

Unregister a comm, and close its counterpart

unregister_target(target_name, f)#

Unregister a callable registered with register_target

Module contents#