将jupyter笔记本转换为nuclio
nuclio的Python项目详细描述
Nuclio Jupyter导出
将jupyter笔记本转换为可以作为nuclio处理程序运行的python代码
用法
在开发时,从nucilo
导入Context
和Event
,并使用它
生成模拟上下文和请求。
# nuclio: ignorefromnuclioimportContext,Eventcontext=Context()event=Event(body='Hello Nuclio')# your code goes here
在您想成为处理程序的单元格中,添加了注释# nuclio:handler
。如果有一个特定的行,你想成为返回的行-
在结尾处添加了# nuclio:return
。
包含# nuclio: ignore
注释的单元格将在导出中被注释掉
过程。
现在在Jupyter笔记本中选择File/Download as/Nuclio
或者您可以运行
jupyter nbconvert --to nuclio example.ipynb
这将用handler函数和所有
带有# nuclio: ignore
的单元格已注释掉。
示例
将生成
# coding: utf-8# In[1]:defgreeting(name):return'Hi '+name+'. How are you?'# In[2]:default_name='Dave'# In[3]:# # nuclio:ignore# from nuclio import Context, Event# context = Context()# event = Event(body=default_name)# In[4]:defhandler(context,event):# nuclio:handlerreturngreeting(event.body)
试试看
您可以构建一个Docker图像并进行尝试
建造
$ docker build -t jupyter-nuclio .
运行
$ docker run -p 8888:8888 jupyter-nuclio
然后在http://localhost:8888打开浏览器,输入密码nuclio
当提示时。
开发
我们使用pipenv作为包管理器。安装 依赖项运行
$ pipenv sync -d
要运行测试,请运行
$ pipenv run python -m pytest -v tests
许可证
Apache2.0(见LICENSE.txt)