jupyter_server.services.sessions package¶
Submodules¶
Tornado handlers for the sessions web service.
Preliminary documentation at https://github.com/ipython/ipython/wiki/IPEP-16%3A-Notebook-multi-directory-dashboard-and-URL-mapping#sessions-api
- class jupyter_server.services.sessions.handlers.SessionHandler(application, request, **kwargs)¶
Bases:
SessionsAPIHandler
A handler for a single session.
- delete(session_id)¶
Delete the session with given session_id.
- get(session_id)¶
Get the JSON model for a single session.
- patch(session_id)¶
Patch updates sessions:
path updates session to track renamed paths
kernel.name starts a new kernel with a given kernelspec
- class jupyter_server.services.sessions.handlers.SessionRootHandler(application, request, **kwargs)¶
Bases:
SessionsAPIHandler
A Session Root API handler.
- get()¶
Get a list of running sessions.
- post()¶
Create a new session.
- class jupyter_server.services.sessions.handlers.SessionsAPIHandler(application, request, **kwargs)¶
Bases:
APIHandler
A Sessions API handler.
- auth_resource = 'sessions'¶
A base class session manager.
- class jupyter_server.services.sessions.sessionmanager.KernelSessionRecord(session_id=None, kernel_id=None)¶
Bases:
object
A record object for tracking a Jupyter Server Kernel Session.
Two records that share a session_id must also share a kernel_id, while kernels can have multiple session (and thereby) session_ids associated with them.
-
kernel_id:
Optional
[str
] = None¶
-
session_id:
Optional
[str
] = None¶
- update(other)¶
Updates in-place a kernel from other (only accepts positive updates
- Return type:
None
-
kernel_id:
- exception jupyter_server.services.sessions.sessionmanager.KernelSessionRecordConflict¶
Bases:
Exception
Exception class to use when two KernelSessionRecords cannot merge because of conflicting data.
- class jupyter_server.services.sessions.sessionmanager.KernelSessionRecordList(*records)¶
Bases:
object
An object for storing and managing a list of KernelSessionRecords.
When adding a record to the list, the KernelSessionRecordList first checks if the record already exists in the list. If it does, the record will be updated with the new information; otherwise, it will be appended.
- get(record)¶
Return a full KernelSessionRecord from a session_id, kernel_id, or incomplete KernelSessionRecord.
- Return type:
- remove(record)¶
Remove a record if its found in the list. If it’s not found, do nothing.
- Return type:
None
- update(record)¶
Update a record in-place or append it if not in the list.
- Return type:
None
- class jupyter_server.services.sessions.sessionmanager.SessionManager(**kwargs: Any)¶
Bases:
LoggingConfigurable
A session manager.
- close()¶
Close the sqlite connection
- property connection¶
Start a database connection
- contents_manager¶
A trait whose value must be an instance of a class in a specified list of classes. The value can also be an instance of a subclass of the specified classes. Subclasses can declare default classes by overriding the klass attribute
- async create_session(path=None, name=None, type=None, kernel_name=None, kernel_id=None)¶
Creates a session and returns its model
- Parameters:
name (ModelName(str)) – Usually the model name, like the filename associated with current kernel.
- Return type:
Dict
[str
,Any
]
- property cursor¶
Start a cursor and create a database called ‘session’
- database_filepath¶
` setting from sqlite3) and does not persist when the current Jupyter Server shuts down.
- Type:
The filesystem path to SQLite Database file (e.g. /path/to/session_database.db). By default, the session database is stored in-memory (i.e. `
- Type:
memory
- async delete_session(session_id)¶
Deletes the row in the session database with given session_id
- get_kernel_env(path, name=None)¶
Return the environment variables that need to be set in the kernel
- Parameters:
path (str) – the url path for the given session.
name (ModelName(str), optional) – Here the name is likely to be the name of the associated file with the current kernel at startup time.
- Return type:
Dict
[str
,str
]
- async get_session(**kwargs)¶
Returns the model for a particular session.
Takes a keyword argument and searches for the value in the session database, then returns the rest of the session’s info.
- Parameters:
**kwargs (dict) – must be given one of the keywords and values from the session database (i.e. session_id, path, name, type, kernel_id)
- Returns:
model – returns a dictionary that includes all the information from the session described by the kwarg.
- Return type:
dict
- async kernel_culled(kernel_id)¶
Checks if the kernel is still considered alive and returns true if its not found.
- Return type:
bool
- kernel_manager¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- async list_sessions()¶
Returns a list of dictionaries containing all the information from the session database
- new_session_id()¶
Create a uuid for a new session
- Return type:
str
- async row_to_model(row, tolerate_culled=False)¶
Takes sqlite database session row and turns it into a dictionary
- async save_session(session_id, path=None, name=None, type=None, kernel_id=None)¶
Saves the items for the session with the given session_id
Given a session_id (and any other of the arguments), this method creates a row in the sqlite session database that holds the information for a session.
- Parameters:
session_id (str) – uuid for the session; this method must be given a session_id
path (str) – the path for the given session
name (str) – the name of the session
type (str) – the type of the session
kernel_id (str) – a uuid for the kernel associated with this session
- Returns:
model – a dictionary of the session model
- Return type:
dict
- async session_exists(path)¶
Check to see if the session of a given name exists
- async start_kernel_for_session(session_id, path, name, type, kernel_name)¶
Start a new kernel for a given session.
- Parameters:
session_id (str) – uuid for the session; this method must be given a session_id
path (str) – the path for the given session - seem to be a session id sometime.
name (str) – Usually the model name, like the filename associated with current kernel.
type (str) – the type of the session
kernel_name (str) – the name of the kernel specification to use. The default kernel name will be used if not provided.
- Return type:
str
- async update_session(session_id, **kwargs)¶
Updates the values in the session database.
Changes the values of the session with the given session_id with the values from the keyword arguments.
- Parameters:
session_id (str) – a uuid that identifies a session in the sqlite3 database
**kwargs (str) – the key must correspond to a column title in session database, and the value replaces the current value in the session with session_id.