Skip to content

Commit fd216d2

Browse files
authored
Merge pull request #356 from cottrell/master
Update docs to be more informative on startup as per issue https://gi…
2 parents e48ea0c + a59189b commit fd216d2

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

docs/source/getting-started.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
This document describes some of the basics of installing and running the
44
Jupyter Kernel Gateway.
55

6-
## Using pip
6+
## Install
7+
### Using pip
78

89
We 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,70 @@ We make stable releases of the kernel gateway to PyPI. You can use `pip` to inst
1213
pip 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+
1526
Once installed, you can use the `jupyter` CLI to run the server.
1627

1728
```bash
1829
# run it with default options
1930
jupyter 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 in [http-mode](http-mode.md) 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
2852
```
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"}}
62+
```
63+
64+
You can also run in the default [websocket-mode](websocket-mode.md):
65+
```bash
66+
jupyter kernelgateway --KernelGatewayApp.api=kernel_gateway.jupyter_websocket --port=10100
67+
[KernelGatewayApp] Jupyter Kernel Gateway at http://127.0.0.1:10100
68+
```
69+
and again notice the output in the logs. This time we didn't point to a specific notebook but you can test against the kernelspecs endpoint or the swagger endpoint:
70+
```bash
71+
curl http://127.0.0.1:10100/api/kernelspecs
72+
{"default": "python3", "kernelspecs": {"python38364bit38conda21f48c44b19044fba5c7aa244072a647": {"name": "python38364bit38conda21f48c44b19044fba5c7aa244072a647", ...
73+
```
74+
75+
For more details running-mode sections [websocket-mode](websocket-mode.md) and [http-mode](http-mode.md).
2976

30-
Once installed, you can use the `jupyter` CLI to run the server as shown above.
77+
**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.**
3178

32-
## Using a docker-stacks image
79+
## Running using a docker-stacks image
3380

3481
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:
3582

0 commit comments

Comments
 (0)