33This document describes some of the basics of installing and running the
44Jupyter Kernel Gateway.
55
6- ## Using pip
6+ ## Install
7+ ### Using pip
78
89We make stable releases of the kernel gateway to PyPI. You can use ` pip ` to install the latest version along with its dependencies.
910
@@ -12,24 +13,57 @@ We make stable releases of the kernel gateway to PyPI. You can use `pip` to inst
1213pip install jupyter_kernel_gateway
1314```
1415
16+ ### Using conda
17+
18+ You can install the kernel gateway using conda as well.
19+
20+ ``` bash
21+ conda install -c conda-forge jupyter_kernel_gateway
22+ ```
23+
24+ ## Running
25+
1526Once installed, you can use the ` jupyter ` CLI to run the server.
1627
1728``` bash
1829# run it with default options
1930jupyter kernelgateway
2031```
2132
22- ## Using conda
33+ For example, if we define an endpoint in a notebook ` ./my_example.ipynb ` as follows:
34+ ``` python
35+ # GET /hello/world
2336
24- You can install the kernel gateway using conda as well.
37+ import json
38+ import requests
39+ import numpy as np
2540
41+ req = json.loads(REQUEST )
42+ res = dict (data = np.random.randn(5 , 4 ).tolist(), request = req)
43+ print (json.dumps(res))
44+ ```
45+ and then run the gateway and point specifically at that notebook, we should see some information printed in the logs:
2646``` bash
27- conda install -c conda-forge jupyter_kernel_gateway
47+ jupyter kernelgateway --KernelGatewayApp.api=kernel_gateway.notebook_http --KernelGatewayApp.seed_uri=./my_example.ipynb --port=10100
48+ [KernelGatewayApp] Kernel started: 12ac2daa-c62a-47e4-964a-336734557656
49+ [KernelGatewayApp] Registering resource: /hello/world, methods: ([' GET' ])
50+ [KernelGatewayApp] Registering resource: /_api/spec/swagger.json, methods: (GET)
51+ [KernelGatewayApp] Jupyter Kernel Gateway at http://127.0.0.1:10100
52+ ```
53+ We can curl against these endpoints to demonstrate it is working:
54+ ``` bash
55+ curl http://127.0.0.1:10100/hello/world
56+ {" data" : [[0.25854873480479607, -0.7997878409880017, 1.1136688704814672, -1.3292395513862103], [1.9879386172897555, 0.43368279132553395, -0.8623363198491706, -0.1571285171759644], [0.4437134294167942, 1.1323758620715763, 1.7350545168735723, -0.7617257690860397], [-0.4219717996309759, 0.2912776236488964, -0.21468140988270742, -0.8286216351049279], [0.5754812112421828, -2.042429681534432, 2.992678912690803, -0.7231031350239057]], " request" : {" body" : " " , " args" : {}, " path" : {}, " headers" : {" Host" : " 127.0.0.1:10100" , " User-Agent" : " curl/7.68.0" , " Accept" : " */*" }}}
57+ ```
58+ and the swagger spec:
59+ ``` bash
60+ curl http://127.0.0.1:10100/_api/spec/swagger.json
61+ {" swagger" : " 2.0" , " paths" : {" /hello/world" : {" get" : {" responses" : {" 200" : {" description" : " Success" }}}}}, " info" : {" version" : " 0.0.0" , " title" : " my_example" }}
2862```
2963
30- Once installed, you can use the ` jupyter ` CLI to run the server as shown above.
64+ ** NOTE: Watch out for notebooks that run things on import as this might cause the gateway server to crash immediately and the log messages are not always obvious. **
3165
32- ## Using a docker-stacks image
66+ ## Running using a docker-stacks image
3367
3468You can add the kernel gateway to any [ docker-stacks] ( https://github.com/jupyter/docker-stacks ) image by writing a Dockerfile patterned after the following example:
3569
0 commit comments