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 ...
随机推荐
- RabbitMQ高级使用
概述 在支付场景中,支付成功后利用RabbitMQ通知交易服务,更新业务订单状态为已支付.但是大家思考一下,如果这里MQ通知失败,支付服务中支付流水显示支付成功,而交易服务中的订单状态却显示未支付,数 ...
- 1+2+...+n
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M 题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.cas ...
- Django 数据迁移报错之“TypeError: __init__() missing 1 required positional argument: 'on_delete'”
当执行 python manage.py makemigrations 出现错误:TypeError: init() missing 1 required positional argument: ' ...
- centos8安装部署RADIUS+MySQLPGSQL高可用架构实现
以下是针对中大型网络的 RADIUS+MySQL/PGSQL高可用方案 的完整实现,包含数据库集成.主备集群部署和Keepalived配置: 一.MySQL/PGSQL数据库集成(以MySQL为例) ...
- python doc转png踩坑历程分享
首先python根据文本内容生成doc,使用的是python-docx库,使用示例如下: from docx import Document from docx.shared import Pt, R ...
- 代码随想录第四天 | 链表part02
两两交换链表中的节点 用虚拟头结点,这样会方便很多. 本题链表操作就比较复杂了,建议大家先看视频,视频里我讲解了注意事项,为什么需要temp保存临时节点. 题目链接/文章讲解/视频讲解: https: ...
- jupyter的使用 -- 快捷键
jupyter的使用 1.快捷键的使用 插入cell:a,b 删除cell:x 执行cell:shift+enter 切换cell的模式:m,y cell执行后,在cell的左侧双击就可以回到cell ...
- Tomcat基础学习
Tomcat简介 Tomcat是一个轻量级的web服务器,也称为web容器,servlet容器.(web服务器可以封装http协议,简化开发.还可以将web项目部署到服务器上,对外提供网上浏览.) T ...
- OceanBase 正式上线 KubeSphere Marketplace
随着云原生与容器化浪潮全面重塑 IT 基础设施,数据库层的"云原生化"也逐渐从趋势演进为现实需求.近日,OceanBase 开源社区的扩展组件 OceanBase Operator ...
- 袋鼠云:拥抱DeepSeek大模型,做Data+AI的长期主义者
<数据资产管理白皮书>下载地址:https://www.dtstack.com/resources/1073/?src=szsm <行业指标体系白皮书>下载地址:https:/ ...