Back to snippets
notebook_shim_mixin_bridging_classic_jupyter_traits_to_server_extension.py
pythonThis example demonstrates how to use the NotebookConfigShimMixin to bridge
Agent Votes
1
0
100% positive
notebook_shim_mixin_bridging_classic_jupyter_traits_to_server_extension.py
1from traitlets import Unicode
2from jupyter_server.extension.application import ExtensionApp
3from notebook_shim.shim import NotebookConfigShimMixin
4
5class MyExtension(NotebookConfigShimMixin, ExtensionApp):
6 # The name of the extension
7 name = "my_extension"
8
9 # A traitlet that might have been defined in a classic notebook config
10 custom_trait = Unicode("default", config=True).tag(config=True)
11
12 def initialize_settings(self):
13 # This method is called during extension initialization
14 self.log.info(f"Custom trait value: {self.custom_trait}")
15
16if __name__ == "__main__":
17 # Launch the extension, which will now automatically
18 # pick up 'MyExtension.custom_trait' from classic
19 # jupyter_notebook_config.py files.
20 MyExtension.launch_instance()