Notebook Client

The bookstore.client.nb_client module

NotebookClient

class bookstore.client.nb_client.NotebookClient(nb_config)

EXPERIMENTAL SUPPORT: Client used to interact with a notebook server from within a notebook.

Parameters:nb_config (dict) – Dictionary of info compatible with creating a LiveNotebookRecord.
nb_config

Dictionary of info compatible with creating a LiveNotebookRecord.

Type:dict
nb_record

LiveNotebookRecord of info for this notebook

Type:LiveNotebookRecord
url

url from nb_record minus final /

Type:str
token

token used for authenticating requests serverside

Type:str
xsrf_token

xsrf_token used in cookie for authenticating requests

Type:str
req_session

Session to be reused across methods

Type:requests.Session
contents_endpoint

Current server’s contents API endpoint.

get_contents(path)

Requests info about current contents from notebook server.

get_kernels()

Requests info about current kernels from notebook server.

get_sessions()

Requests info about current sessions from notebook server.

headers

Default headers to be shared across requests.

kernels

Current notebook kernels. Reissues request on each call.

kernels_endpoint

Current server’s kernels API endpoint.

sessions

Current notebook sessions. Reissues request on each call.

sessions_endpoint

Current server’s kernels API endpoint.

setup_auth()

Sets up token access for authorizing requests to notebook server.

This sets the notebook token as self.token and the xsrf_token as self.xsrf_token.

setup_request_sessions()

Sets up a requests.Session object for sharing headers across API requests.

NotebookClientCollection

class bookstore.client.nb_client.NotebookClientCollection

EXPERIMENTAL SUPPORT: Representation of a collection of notebook clients

classmethod current_server()

class method for current notebook server

CurrentNotebookClient

class bookstore.client.nb_client.CurrentNotebookClient

EXPERIMENTAL SUPPORT: Represents the currently active notebook client.

connection_file

Connection file for connecting to current notebook’s kernel.

kernel_id

Kernel id for identifying which notebook is currently being used by this session.

LiveNotebookRecord

class bookstore.client.nb_client.LiveNotebookRecord

Representation of live notebook server.

This is a record of an object returned by notebook.notebookapp.list_running_servers().

Example

[{'base_url': '/',
'hostname': 'localhost',
'notebook_dir': '/Users/mpacer/jupyter/eg_notebooks',
'password': False,
'pid': 96033,
'port': 8888,
'secure': False,
'token': '',
'url': 'http://localhost:8888/'}]
base_url

Alias for field number 0

hostname

Alias for field number 1

notebook_dir

Alias for field number 2

password

Alias for field number 3

pid

Alias for field number 4

port

Alias for field number 5

secure

Alias for field number 6

token

Alias for field number 7

url

Alias for field number 8

KernelInfo

class bookstore.client.nb_client.KernelInfo(*args, id, name, last_activity, execution_state, connections)

Representation of kernel info returned by the notebook’s /api/kernel endpoint.

id
Type:str
name
Type:str
last_activity
Type:str
execution_state
Type:str
connections
Type:int

Example

{id: 'f92b7c8b-0858-4d10-903c-b0631540fb36',
name: 'dev',
last_activity: '2019-03-14T23:38:08.137987Z',
execution_state: 'idle',
connections: 0}

NotebookSession

class bookstore.client.nb_client.NotebookSession(*args, path, name, type, kernel, notebook={}, **kwargs)

Representation of session info returned by the notebook’s /api/sessions/ endpoint.

id
Type:str
path
Type:str
name
Type:str
type
Type:str
kernel
Type:KernelInfo
notebook
Type:dict
model

Record of the raw response (without converting the KernelInfo).

Type:dict

Example

{id: '68d9c58f-c57d-4133-8b41-5ec2731b268d',
 path: 'Untitled38.ipynb',
 name: '',
 type: 'notebook',
 kernel: KernelInfo(id='f92b7c8b-0858-4d10-903c-b0631540fb36',
                    name='dev',
                    last_activity='2019-03-14T23:38:08.137987Z',
                    execution_state='idle',
                    connections=0),
notebook: {'path': 'Untitled38.ipynb', 'name': ''}}

Helper Function

bookstore.client.nb_client.extract_kernel_id(connection_file)

Get the kernel id string from a file