3
3
This document describes some of the basics of installing and running the
4
4
Jupyter Kernel Gateway.
5
5
6
- ## Using pip
6
+ ## Install
7
+ ### Using pip
7
8
8
9
We make stable releases of the kernel gateway to PyPI. You can use ` pip ` to install the latest version along with its dependencies.
9
10
@@ -12,24 +13,57 @@ We make stable releases of the kernel gateway to PyPI. You can use `pip` to inst
12
13
pip install jupyter_kernel_gateway
13
14
```
14
15
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
+
15
26
Once installed, you can use the ` jupyter ` CLI to run the server.
16
27
17
28
``` bash
18
29
# run it with default options
19
30
jupyter kernelgateway
20
31
```
21
32
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
23
36
24
- You can install the kernel gateway using conda as well.
37
+ import json
38
+ import requests
39
+ import numpy as np
25
40
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:
26
46
``` 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" }}
28
62
```
29
63
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. **
31
65
32
- ## Using a docker-stacks image
66
+ ## Running using a docker-stacks image
33
67
34
68
You 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:
35
69
0 commit comments