Skip to main content

Convert Jupyter notebook to nuclio

Project description

nuclio Jupyter Export

Build Status License

Convert Jupyter notebook to Python code that can run as nuclio handler


pip install nuclio-jupyter

Install in Notebook

Run the following in a cell

# nuclio: ignore
!pip install nuclio-jupyter


When developing, import Event from nucilo and use it to generate a mock request events.

import nuclio

This will inject a context object into the notebook namespace.


# nuclio: ignore
from nuclio import Event

event = Event(body='Hello Nuclio')
# your code goes here

In the cell you'd like to become the handler, added the magic %%nuclio handler If there's a specific line you'd like to be the returned one - added # nuclio:return at the end of it.

Cells containing # nuclio: ignore comment will be omitted in the export process.

Now choose File/Download as/Nuclio in Jupyter notebook (you might need to mark the notebook as Trusted in order for the Nuclio option to show)

Or you can run

jupyter nbconvert --to nuclio example.ipynb

This will create with your code wrapped in handler function and function.yaml nuclio configuration file.


Will generate a zip file with

# Generated by nuclio.export.NuclioExporter on 2018-12-10 08:26:39.086907

import nuclio

def handler(context, event):
   msg = 'Hello ' + str(event.body)
   return msg # nuclio: return

and function.yaml

# Generated by nuclio.export.NuclioExporter on 2018-12-10 08:26:39.095522
kind: Function
metadata: {}
 runtime: python:3.6
 handler: handler:handler
   - name: API_KEY
     value: '1234'
   - name: NUM_JOBS
     value: '2'
   - name: PASSWORD
     value: t0ps3cr3t
   - name: USER
     value: guazio
 - apt-get install -y libyaml-dev

Other Notebooks

We currently don't support Jupyter Lab, Google Colaboratory, Kaggle Notebooks and others.

You can use nuclio.print_handler_code or nuclio.save_handler_code to print/save the handler code and then copy&paste it to the nuclio dashboard.

Try It Out

You can build a docker image and try it out


$ docker build -t jupyter-nuclio .


$ docker run -p 8888:8888 jupyter-nuclio

Then open your browser at http://localhost:8888


We're using pipenv as package manager. To install dependencies run

$ pipenv sync -d

To run the tests run

$ pipenv run python -m pytest -v tests


Apache 2.0 (see LICENSE.txt)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
nuclio-jupyter-0.6.11.tar.gz (37.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page