This documentation describes the current API for IPython Notebook's web-services. In handling HTTP request, we pass all information between the server and client using JSON standard models. Each standard model is shown at the beginning of the sections below. This format adheres to the principles described in RESTful web-services.
- Notebooks
- List notebooks in root directory
- Create new notebook
- List notebooks in named directory
- Open the named noteboko in subdirectory
- Change notebook's standard model and save modified notebook
- Delete a notebook in subdirectory
- Sessions
- List all sessions
- Create a session
- Get session information
- Make changes to a session
- Delete a session/kill kernel
- Kernels
- List active kernels
- Start a kernel
- Shutdown a kernel
- Contents
This web-service handles all HTTP requests on ".ipynb" files. The standard notebooks model in JSON is shown below:
{
"name": "Untitled0.ipynb",
"path": "/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
GET /api/notebooks
Returns a list of standard notebook models in the root directory.
[
{
"name": "notebook1.ipynb",
"path": "/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
},
{
"name": "notebook2.ipynb",
"path": "/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
]
POST /api/notebooks
Creates a new notebook and names it with "Untitled#.ipynb" with some incremented number. Returns the JSON model of the created notebook.
{
"name": "Untitled0.ipynb",
"path": "/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
GET /api/notebooks/foo/bar/
Returns a list of standard notebook models in the "/foo/bar/" directory.
[
{
"name": "notebook1.ipynb",
"path": "/foo/bar/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
},
{
"name": "notebook2.ipynb",
"path": "/foo/bar/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
]
GET /api/notebooks/foo/bar/notebook1.ipynb
Returns the standard notebook model for that named notebook and "content" value is used to display the html representation of the notebook:
{
"name": "notebook1.ipynb",
"path": "/foo/bar/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
PATCH /api/notebooks/foo/bar/notebook1.ipynb
Changes values of the standard notebook model for the named notebook and keep all unchanged keys. If the contents of the notebook are changed or modified, this is the HTTP request to save notebook's changes.
{
"name": "notebook1.ipynb",
"path": "/foo/bar/",
"modified": "new_date",
"created": "date",
"content":{
"metadata":{"new content"},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
The standard model can be changed using a PUT
HTTP request, but all unchanged keys are deleted.
PUT /api/notebooks/foo/bar/notebook1.ipynb
Changes values of the standard notebook model for the named notebook and keep all unchanged keys:
{
"name": "notebook1.ipynb",
"path": "/foo/bar/",
"modified": "new_date",
"created": "date",
"content":{
"metadata":{"new content"},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
DELETE /api/notebooks/foo/bar/notebook1.ipynb
Deletes the notebook's standard model from the named location.
The contents webservice is designed to deal with HTTP requests on items other than IPython notebooks (i.e. files and folders within the user's filesystem). This webservice will eventually include a text editor for files that are not notebooks. The standard model for the contents webservice is shown below:
{
"name": "file.txt",
"path": "/my/path",
"content": "..content of file..",
"type": (file|dir|etc),
"size": 2345,
"encoding": "base64",
"modified": "date",
"created": {}
}
A session maps a notebook to a kernel. When a notebook is opened, a session is created and a kernel is started. The standard model for a session is shown below:
{
"session_id": "d7753a2c-14da-4ae9-95b8-7b96b11aebe7",
"notebook_name": "notebook1.ipynb",
"notebook_path": "/foo/bar/",
"kernel": {
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/foo/bar"
}
}
GET /api/sessions
Returns a list of standard session models.
[
{
"session_id": "d7753a2c-14da-4ae9-95b8-7b96b11aebe7",
"notebook_name": "notebook1.ipynb",
"notebook_path": "/foo/bar/",
"kernel": {
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/foo/bar"
}
},
{
"session_id": "b4dfa62c-0e91-4111-9d1f-0c59069c6602",
"notebook_name": "notebook1.ipynb",
"notebook_path": "/foo/bar/",
"kernel": {
"kernel_id": "4adcb1a3-2e7f-4e82-af2e-d76f5815467a",
"ws_url": "ws://myhost/foo/bar"
}
}
]
POST /api/sessions
Requires a JSON standard notebook model to be sent to the server before a session is created.
{
"name": "Untitled0.ipynb",
"path": "/foo/bar/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
{
"session_id": "d7753a2c-14da-4ae9-95b8-7b96b11aebe7",
"notebook_name": "Untitled0.ipynb",
"notebook_path": "/foo/bar/",
"kernel": {
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/foo/bar"
}
}
GET /api/sessions/d7753a2c-14da-4ae9-95b8-7b96b11aebe7
{
"session_id": "d7753a2c-14da-4ae9-95b8-7b96b11aebe7",
"notebook_name": "notebook1.ipynb",
"notebook_path": "/foo/bar/",
"kernel": {
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/foo/bar"
}
}
This can be used to rename the notebook, or move a file to a new directory.
PUT /api/sessions/d7753a2c-14da-4ae9-95b8-7b96b11aebe7
{
"name": "new_name.ipynb",
"path": "/foo/bar/",
"modified": "date",
"created": "date",
"content":{
"metadata":{},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": []
}
}
{
"session_id": "d7753a2c-14da-4ae9-95b8-7b96b11aebe7",
"notebook_name": "new_name.ipynb",
"notebook_path": "/foo/bar/",
"kernel": {
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/foo/bar"
}
}
DELETE /api/sessions/d7753a2c-14da-4ae9-95b8-7b96b11aebe7
Deletes the sessions and kills the kernel held in the session.
This webservice managers all running kernels. The standard kernel model in JSON is shown below:
{
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/"
}
GET /api/kernels
[
{
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/"
},
{
"kernel_id": "4f567fb0-2455-4bc9-a137-69daac27e9a2",
"ws_url": "ws://myhost/"
}
]
POST /api/kernels
Starts a kernel and returns:
{
"kernel_id": "b7e1a137-a434-4598-846e-ee51fb06c306",
"ws_url": "ws://myhost/"
}
DELETE /api/kernels/0899e220-ab81-43c2-a97a-ff1af4118598
Kills the kernel and deletes the ID.