SciTech-BigDataAIML-Jupyter- 扩展Jupyter 的 Notebook + LSP(语言服务) 的文档 Extending the Notebook
https://jupyterlab-lsp.readthedocs.io/en/latest/Installation.html
https://github.com/jupyter-lsp/jupyterlab-lsp
- Jupyter lab extension example:
jupyter_voicepilot:
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyter_voicepilot-0.1.2.dist-info/*
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/jupyter_voicepilot/*
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/install.json
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/package.json
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/schemas/voicepilot/package.json.orig
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/schemas/voicepilot/plugin.json
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/484.89ad9e9e0e2c63db0a8c.js
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/485.e650a21cfb90e6407c5c.js
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/496.f4837d51166d7104dd2f.js
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/747.5f1ebb2e2b503421e9d6.js
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/remoteEntry.8801bf73507f23e3b027.js
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/style.js
/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot/static/third-party-licenses.json
init.py:
from ._version import __version__
def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": "voicepilot"}]
_version.py:
# This file is auto-generated by Hatchling. As such, do not modify - track in version control, e.g. be sure to add to .gitignore
__version__ = VERSION = '0.1.2'
而 jupyter_voicepilot 这个扩展的应用部分存放在:<PYTHON_INSTALL_DIR>/share/jupyter/labextensions/voicepilot
即:/Library/Frameworks/Python.framework/Versions/3.12/share/jupyter/labextensions/voicepilot
Docs » Extending the Notebook » Custom request handlers Edit on GitHub
Note
You are not reading the most recent version of this documentation. v7.0.6 is the latest version available.
Custom request handlers
The notebook webserver can be interacted with using a well defined RESTful API. You can define custom RESTful API handlers in addition to the ones provided by the notebook. As described below, to define a custom handler you need to first write a notebook server extension. Then, in the extension, you can register the custom handler.
Writing a notebook server extension
The notebook webserver is written in Python, hence your server extension should be written in Python too. Server extensions, like IPython extensions, are Python modules that define a specially named load function, load_jupyter_server_extension. This function is called when the extension is loaded.
def load_jupyter_server_extension(nb_server_app):
"""
Called when the extension is loaded.
Args:
nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance.
"""
pass
To get the notebook server to load your custom extension, you’ll need to add it to the list of extensions to be loaded. You can do this using the config system. NotebookApp.server_extensions is a config variable which is an array of strings, each a Python module to be imported. Because this variable is notebook config, you can set it two different ways, using config files or via the command line.
For example, to get your extension to load via the command line add a double dash before the variable name, and put the Python array in double quotes. If your package is “mypackage” and module is “mymodule”, this would look like jupyter notebook --NotebookApp.server_extensions="['mypackage.mymodule']" . Basically the string should be Python importable.
Alternatively, you can have your extension loaded regardless of the command line args by setting the variable in the Jupyter config file. The default location of the Jupyter config file is ~/.jupyter/profile_default/jupyter_notebook_config.py. Then, inside the config file, you can use Python to set the variable. For example, the following config does the same as the previous command line example [1].
c = get_config()
c.NotebookApp.server_extensions = [
'mypackage.mymodule'
]
Before continuing, it’s a good idea to verify that your extension is being loaded. Use a print statement to print something unique. Launch the notebook server and you should see your statement printed to the console.
Registering custom handlers
Once you’ve defined a server extension, you can register custom handlers because you have a handle to the Notebook server app instance (nb_server_app above). However, you first need to define your custom handler. To declare a custom handler, inherit from notebook.base.handlers.IPythonHandler. The example below[1] is a Hello World handler:
from notebook.base.handlers import IPythonHandler
class HelloWorldHandler(IPythonHandler):
def get(self):
self.finish('Hello, world!')
The Jupyter Notebook server use Tornado as its web framework. For more information on how to implement request handlers, refer to the Tornado documentation on the matter.
After defining the handler, you need to register the handler with the Notebook server. See the following example:
web_app = nb_server_app.web_app
host_pattern = '.*$'
route_pattern = url_path_join(web_app.settings['base_url'], '/hello')
web_app.add_handlers(host_pattern, [(route_pattern, HelloWorldHandler)])
Putting this together with the extension code, the example looks like the following:
from notebook.utils import url_path_join
from notebook.base.handlers import IPythonHandler
class HelloWorldHandler(IPythonHandler):
def get(self):
self.finish('Hello, world!')
def load_jupyter_server_extension(nb_server_app):
"""
Called when the extension is loaded.
Args:
nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance.
"""
web_app = nb_server_app.web_app
host_pattern = '.*$'
route_pattern = url_path_join(web_app.settings['base_url'], '/hello')
web_app.add_handlers(host_pattern, [(route_pattern, HelloWorldHandler)])
References: 1. Peter Parente’s Mindtrove
Copyright 2015, Jupyter Team, https://jupyter.org. Revision 2c96ad2d.
SciTech-BigDataAIML-Jupyter- 扩展Jupyter 的 Notebook + LSP(语言服务) 的文档 Extending the Notebook的更多相关文章
- 使用Jupyter Notebook编写技术文档
1.jupyter Notebook的组成 这里它的组件及其工程构成,帮助大家更好的用好jupyter Notebook 组件 Jupyter Notebook结合了三个组件: 笔记本Web应用程序: ...
- Blocking Cross Origin API request for /api/contents Creating Notebook Failed An error occurred while creating a new notebook.
anacoda安装的jupyter,使用nginx进行了转发,远程访问可以进去,但是创建文件和创建目录都会报错 浏览器页面报错: 第一次使用jupyter创建python时错误:Creating No ...
- Asp.net 面向接口可扩展框架之类型转化基础服务
新框架正在逐步完善,可喜可贺的是基础服务部分初具模样了,给大家分享一下 由于基础服务涉及面太广,也没开发完,这篇只介绍其中的类型转化部分,命名为类型转化基础服务,其实就是基础服务模块的类型转化子模块 ...
- MFC单文档自定义扩展名及添加图标报Assertion错误
忽然无聊的想给自己写的程序保存的文件使用自己的名字简写作为后缀,于是有了下文. IDR_MAINFRAME格式介绍 IDR_MAINFRAME字符串资源中包含7个子串,分别以/n结束,即如下格式: & ...
- 可扩展标记语言XML之二:XML语言格式规范、文档组成
大家好,小乐又来了,好久不见!这次接着上次可扩展标记语言XML之一:XML概念,作用,示例,继续讲述XML. 一.格式良好的 xml 1.语法规范: 1).必须有 XML 文档声明: <?xml ...
- 真香警告!扩展 swagger支持文档自动列举所有枚举值
承接上篇文章 <一站式解决使用枚举的各种痛点> 文章最后提到:在使用 swagger 来编写接口文档时,需要告诉前端枚举类型有哪些取值,每次增加取值之后,不仅要改代码,还要找到对应的取值在 ...
- jupyter扩展插件Nbextensions使用
本节主要解释jupyter中各种插件 原创文章,转载请务必注明原作者出处:http://www.cnblogs.com/cloud-ken/p/7401534.html Exercise Exerci ...
- Ubuntu 16.04上anaconda安装和使用教程,安装jupyter扩展等 | anaconda tutorial on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/23014ca5/,欢迎阅读最新内容! anaconda tutorial on ubuntu 16.04 Guide versio ...
- Ubuntu环境下使用Jupyter Notebook查找桌面.csv文档的方法
这个问题困扰了我很久,最后在一个老师发来的完成结果里找到了答案.(奇怪的是教材里没有.老师也不讲.尤其是百度也没有啊啊啊啊) 好了进入正题.教材里的原话是这样的 这行代码实现的环境应该是在window ...
- Netflix 开源 Polynote:对标 Jupyter,一个笔记本运行多种语言
谈到数据科学领域的开发工具,Jupyter 无疑是非常知名的一种.它具有灵活高效的特点,非常适合进行开发.调试.分享和教学.近日,Netflix(奈飞)居然也玩起了跨界,他们开源了一个名为 Polyn ...
随机推荐
- ESP32S3 BLE_HID的编程实现
ESP32S3 BLE_HID的编程实现 BLE是低功耗蓝牙,HID是Human Interface Device,也就是人机接口设备. 主要用于无线连接并传输用户输入数据(如按键.触控.手势等). ...
- 【记录】OJ|区间DP|石子合并(环形)
1. 题干 描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出一个算法,计算出将N堆石子 ...
- bat文件备份数据库
@echo off/*获取当前日期*/ set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%" /*数据库自带的备份脚本的存放地址 --opt -u ...
- java数组--对象数组的随机赋值及其他
包含考点: 对象数组的随机赋值 浮点数的指定位数 换用思路进行对象数组的某一属性进行排序 现有Book类,定义如下: private String author; private String ISB ...
- linux 的 Docker 配置(版本24.04)
linux 的docker配置(版本24.04) 这里默认是server版本的, 个人感觉好用,资源消耗少 1.配置ssh连接 个人习惯用ssh连接使用 (如果失败,先配置下一步的换源) sudo a ...
- Manim实现旋转变色特效
在数学动画的世界里,旋转与变色特效无疑是最能吸引观众眼球的元素之一. 今天,就让我们一起探索如何使用Manim框架来实现自定义的旋转变色特效吧! 1. 实现原理 Manim的动画魔法源于Animati ...
- Kubernetes控制器-Deployment
Kubernetes控制器-Deployment 我们已经知道ReplicaSet控制器是用来维护集群中运行的Pod数量的,但是往往在实际操作时候,我们反而不去直接使用RS,而是使用更上层的控制器,比 ...
- 如何给 GitHub Copilot "洗脑”,让 AI 精准遵循指令产出高质量代码
引子 最近在项目中使用 GitHub Copilot 的过程中,我发现了一个很有趣的现象. 当我让 Copilot 帮我写代码时,它总是热情满满地给出一大段实现.但当我仔细审视这些代码时,却经常会发现 ...
- 官宣 | 袋鼠云获过亿元C+轮融资,深耕国产自研数字化技术与服务
近日,国内领先的数字化技术与服务提供商--袋鼠云宣布完成过亿元C+轮融资,本轮融资由源星昱瀚基金.国中资本.深创投投资. 本轮融资资金将主要用于袋鼠云核心产品的研发.产品生态体系建设和市场营销推广等方 ...
- 想要用Altair的仿真软件,记住这个入门级配置
如果你想使用Altair的仿真软件,以下是一些入门级配置的建议. 首先,你需要确保你的计算机满足以下要求: 操作系统:Altair支持多种操作系统,包括Windows.Linux和Mac OS.你需要 ...