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

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.4.3.tar.gz (31.2 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: nuclio-jupyter-0.4.3.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for nuclio-jupyter-0.4.3.tar.gz
Algorithm Hash digest
SHA256 6bece253e7df0b058466ce32b3be669c6114353e4e99d12b2e3a666e41e918c6
MD5 030b4a7a224c6573e8b417f793b9d062
BLAKE2b-256 834bc60e82e654bcab9394b1afa6d66b2b6a04be4cb54a7cec67ff0e07076dbe

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