Convert Jupyter notebook to nuclio
Project description
nuclio Jupyter Export
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 ' + evt.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
build:
commands:
- ls
- apt-get install -y libyaml-dev
- ls /var
- ping -c 3 google.com
kind: Function
metadata: {}
spec:
env:
API_KEY: '1234'
NUM_JOBS: '2'
PASSWORD: t0ps3cr3t
USER: iguazio
handler: handler:handler
runtime: python:3.6
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
File details
Details for the file nuclio-jupyter-0.4.0.tar.gz.
File metadata
- Download URL: nuclio-jupyter-0.4.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a27dc8dc2ea3d46b22bcffea90f03e4c595f2375906d6964b0d81964ed5d291
|
|
| MD5 |
19631f65d083e60843a46916ea46da0c
|
|
| BLAKE2b-256 |
b922ebb8a3ffa50f7dd6890b18fc9873309a9c378611c4cdf263e4edf7b520a5
|