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

Installing

pip install nuclio-jupyter

Install in Notebook

Run the following in a cell

# nuclio: ignore
!pip install nuclio-jupyter

Usage

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.

Then

# 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 example.zip with your code wrapped in handler function and function.yaml nuclio configuration file.

Example

Will generate a zip file with

handler.py

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

import nuclio

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

and function.yaml

# Generated by nuclio.export.NuclioExporter on 2018-12-10 08:26:39.095522
apiVersion: nuclio.io/v1
kind: Function
metadata: {}
spec:
 runtime: python:3.6
 handler: handler:handler
 env:
   - name: API_KEY
     value: '1234'
   - name: NUM_JOBS
     value: '2'
   - name: PASSWORD
     value: t0ps3cr3t
   - name: USER
     value: guazio
build:
 commands:
 - 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

Build

$ docker build -t jupyter-nuclio .

Run

$ docker run -p 8888:8888 jupyter-nuclio

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

Developing

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

Licence

Apache 2.0 (see LICENSE.txt)

Project details


Release history Release notifications | RSS feed

This version

0.6.7

Download files

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

Source Distribution

nuclio-jupyter-0.6.7.tar.gz (34.8 kB view details)

Uploaded Source

File details

Details for the file nuclio-jupyter-0.6.7.tar.gz.

File metadata

  • Download URL: nuclio-jupyter-0.6.7.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for nuclio-jupyter-0.6.7.tar.gz
Algorithm Hash digest
SHA256 c6e66516e52e2c505c7f6a0ff3eb206fb784f24c8c25194b6f91aa45d60a0ec4
MD5 86d5cfaa15c9f671b6d8294874bc8fae
BLAKE2b-256 97ab199bcf03e4a679f3d323854120fda860c9fe7fa5f4ed507480a389312561

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page