Skip to content

Notebook Integration

Use the DesignerAdapter API to open the designer interface on a topology instanace within a cell when running in a colab or jupyter notebook

DesignerAdapter

Bases: Adapter

Source code in hyrrokkin/notebook_integration/designer_adapter.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class DesignerAdapter(Adapter):

    def __init__(self, topology:Topology, port:int|None=None, quiet:bool=True):
        """
        Start a service supporting the opening hyrrokkin's designer UI inside a jupyter or colab notebook.

        Args:
            topology: a topology instance to work with
            port: a port number (optional).  If not provided, may be selected using portpicker with a fallback to 9103.
            quiet: suppress messages except for essential ones
        """
        super().__init__(port)
        self.topology = topology

        self.endpoint = TopologyEndpoint("localhost", self.port, "", self.topology, start_callback=lambda success:self.startup_callback(success),
                                         quiet=quiet)
        self.endpoint.start()
        self.wait_for_startup()

    def open_designer(self, window_width:int|str="95%", window_height:int|str=600):
        """
        Open the designer window in a notebook cell

        Args:
            window_width: the width of the designer window in pixels or as a string percentage
            window_height: the height of the designer window in pixels or as a string percentage
        """
        if not self.running:
            print("Unable to open - notebook adapter was closed")
            return
        self.open_url("topology-designer.html", window_width=window_width, window_height=window_height)

    def open_node(self, node_id, page_id="", language="", window_width="95%", window_height=600):
        """
        Open a node's page in a notebook cell

        Args:
            node_id: the node's ID
            page_id: the page's ID.  use the node's first page if not given.
            language: the language code to localise the page (leave empty if no localisation or use the default language)
            window_width: the width of the window in pixels or as a string percentage
            window_height: the height of the window in pixels or as a string percentage
        """
        node_type = self.topology.get_type_for_node(node_id)
        if node_type is None:
            print("No such node exists")
            return
        (package_id, node_type_id) = node_type
        page_url, page_id = self.topology.get_page_url_for_node(package_id, node_type_id, page_id, for_language=language)
        if page_url is None:
            print("No such page exists")
            return
        url = f"package/{package_id}/{page_url}?node_id={node_id}&page_id={page_id}"
        if language:
            url += f"&language={language}"
        self.open_url(url, window_width=window_width, window_height=window_height)

    def open_configuration(self, package_id, page_id="", language="", window_width="95%", window_height=600):
        """
        Open a package configuration page in a notebook cell

        Args:
            package_id: the package's ID
            page_id: the page's ID.  use the package configuration's first page if not given.
            language: the language code to localise the page (leave empty if no localisation or use the default language)
            window_width: the width of the window in pixels or as a string percentage
            window_height: the height of the window in pixels or as a string percentage
        """
        page_url, page_id = self.topology.get_page_url_for_configuration(package_id, page_id, for_language=language)
        url = f"package/{package_id}/{page_url}?package_id={package_id}&page_id={page_id}"
        if language:
            url += f"&language={language}"
        self.open_url(url, window_width=window_width, window_height=window_height)

__init__(topology, port=None, quiet=True)

Start a service supporting the opening hyrrokkin's designer UI inside a jupyter or colab notebook.

Parameters:

Name Type Description Default
topology Topology

a topology instance to work with

required
port int | None

a port number (optional). If not provided, may be selected using portpicker with a fallback to 9103.

None
quiet bool

suppress messages except for essential ones

True
Source code in hyrrokkin/notebook_integration/designer_adapter.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def __init__(self, topology:Topology, port:int|None=None, quiet:bool=True):
    """
    Start a service supporting the opening hyrrokkin's designer UI inside a jupyter or colab notebook.

    Args:
        topology: a topology instance to work with
        port: a port number (optional).  If not provided, may be selected using portpicker with a fallback to 9103.
        quiet: suppress messages except for essential ones
    """
    super().__init__(port)
    self.topology = topology

    self.endpoint = TopologyEndpoint("localhost", self.port, "", self.topology, start_callback=lambda success:self.startup_callback(success),
                                     quiet=quiet)
    self.endpoint.start()
    self.wait_for_startup()

open_configuration(package_id, page_id='', language='', window_width='95%', window_height=600)

Open a package configuration page in a notebook cell

Parameters:

Name Type Description Default
package_id

the package's ID

required
page_id

the page's ID. use the package configuration's first page if not given.

''
language

the language code to localise the page (leave empty if no localisation or use the default language)

''
window_width

the width of the window in pixels or as a string percentage

'95%'
window_height

the height of the window in pixels or as a string percentage

600
Source code in hyrrokkin/notebook_integration/designer_adapter.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def open_configuration(self, package_id, page_id="", language="", window_width="95%", window_height=600):
    """
    Open a package configuration page in a notebook cell

    Args:
        package_id: the package's ID
        page_id: the page's ID.  use the package configuration's first page if not given.
        language: the language code to localise the page (leave empty if no localisation or use the default language)
        window_width: the width of the window in pixels or as a string percentage
        window_height: the height of the window in pixels or as a string percentage
    """
    page_url, page_id = self.topology.get_page_url_for_configuration(package_id, page_id, for_language=language)
    url = f"package/{package_id}/{page_url}?package_id={package_id}&page_id={page_id}"
    if language:
        url += f"&language={language}"
    self.open_url(url, window_width=window_width, window_height=window_height)

open_designer(window_width='95%', window_height=600)

Open the designer window in a notebook cell

Parameters:

Name Type Description Default
window_width int | str

the width of the designer window in pixels or as a string percentage

'95%'
window_height int | str

the height of the designer window in pixels or as a string percentage

600
Source code in hyrrokkin/notebook_integration/designer_adapter.py
43
44
45
46
47
48
49
50
51
52
53
54
def open_designer(self, window_width:int|str="95%", window_height:int|str=600):
    """
    Open the designer window in a notebook cell

    Args:
        window_width: the width of the designer window in pixels or as a string percentage
        window_height: the height of the designer window in pixels or as a string percentage
    """
    if not self.running:
        print("Unable to open - notebook adapter was closed")
        return
    self.open_url("topology-designer.html", window_width=window_width, window_height=window_height)

open_node(node_id, page_id='', language='', window_width='95%', window_height=600)

Open a node's page in a notebook cell

Parameters:

Name Type Description Default
node_id

the node's ID

required
page_id

the page's ID. use the node's first page if not given.

''
language

the language code to localise the page (leave empty if no localisation or use the default language)

''
window_width

the width of the window in pixels or as a string percentage

'95%'
window_height

the height of the window in pixels or as a string percentage

600
Source code in hyrrokkin/notebook_integration/designer_adapter.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def open_node(self, node_id, page_id="", language="", window_width="95%", window_height=600):
    """
    Open a node's page in a notebook cell

    Args:
        node_id: the node's ID
        page_id: the page's ID.  use the node's first page if not given.
        language: the language code to localise the page (leave empty if no localisation or use the default language)
        window_width: the width of the window in pixels or as a string percentage
        window_height: the height of the window in pixels or as a string percentage
    """
    node_type = self.topology.get_type_for_node(node_id)
    if node_type is None:
        print("No such node exists")
        return
    (package_id, node_type_id) = node_type
    page_url, page_id = self.topology.get_page_url_for_node(package_id, node_type_id, page_id, for_language=language)
    if page_url is None:
        print("No such page exists")
        return
    url = f"package/{package_id}/{page_url}?node_id={node_id}&page_id={page_id}"
    if language:
        url += f"&language={language}"
    self.open_url(url, window_width=window_width, window_height=window_height)

Use the DirectoryAdapter API to open the directory interface within a cell

DirectoryAdapter

Bases: Adapter

Source code in hyrrokkin/notebook_integration/directory_adapter.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class DirectoryAdapter(Adapter):

    def __init__(self, topology_directory:TopologyDirectory, port:int|None=None, quiet:bool=True):
        """
        Start a service supporting the opening hyrrokkin's directory UI inside a jupyter or colab notebook.

        Args:
            topology_directory: a TopologyDirectory instance to work with
            port: a port number (optional).  If not provided, may be selected using portpicker with a fallback to 9102.
            quiet: suppress messages except for essential ones
        """
        super().__init__(port)

        self.topology_directory = topology_directory

        self.endpoint = DirectoryEndpoint("localhost", self.port, "", self.topology_directory,
                                     start_callback=lambda success: self.startup_callback(success),
                                     quiet=quiet)
        self.endpoint.start()
        self.wait_for_startup()

    def open(self, window_width:int|str="95%", window_height:int|str=600):
        self.open_url("topology-directory.html", window_width=window_width,
                                   window_height=window_height)

__init__(topology_directory, port=None, quiet=True)

Start a service supporting the opening hyrrokkin's directory UI inside a jupyter or colab notebook.

Parameters:

Name Type Description Default
topology_directory TopologyDirectory

a TopologyDirectory instance to work with

required
port int | None

a port number (optional). If not provided, may be selected using portpicker with a fallback to 9102.

None
quiet bool

suppress messages except for essential ones

True
Source code in hyrrokkin/notebook_integration/directory_adapter.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def __init__(self, topology_directory:TopologyDirectory, port:int|None=None, quiet:bool=True):
    """
    Start a service supporting the opening hyrrokkin's directory UI inside a jupyter or colab notebook.

    Args:
        topology_directory: a TopologyDirectory instance to work with
        port: a port number (optional).  If not provided, may be selected using portpicker with a fallback to 9102.
        quiet: suppress messages except for essential ones
    """
    super().__init__(port)

    self.topology_directory = topology_directory

    self.endpoint = DirectoryEndpoint("localhost", self.port, "", self.topology_directory,
                                 start_callback=lambda success: self.startup_callback(success),
                                 quiet=quiet)
    self.endpoint.start()
    self.wait_for_startup()