API Reference

class sas_kernel.kernel.SASKernel(**kwargs)

Bases: metakernel._metakernel.MetaKernel

SAS Kernel for Jupyter implementation. This module relies on SASPy

Display(*args, **kwargs)
Error(*args, **kwargs)
Print(*args, **kwargs)
Write(message)
abort_request(stream, ident, parent)

abort a specific msg by id

aborted

An instance of a Python set.

add_traits(**traits)

Dynamically add trait attributes to the HasTraits instance.

apply_request(stream, ident, parent)
banner = 'SAS Kernel'
call_magic(line)

Given an line, such as “%download http://example.com/”, parse and execute magic.

class_config_rst_doc()

Generate rST documentation for this class’ config options.

Excludes traits defined on parent classes.

class_config_section()

Get the config class config section

class_get_help(inst=None)

Get the help string for this class in ReST format.

If inst is given, it’s current trait values will be used in place of class defaults.

class_get_trait_help(trait, inst=None)

Get the help string for a single trait.

If inst is given, it’s current trait values will be used in place of the class default.

class_own_trait_events(name)

Get a dict of all event handlers defined on this class, not a parent.

Works like event_handlers, except for excluding traits from parents.

class_own_traits(**metadata)

Get a dict of all the traitlets defined on this class, not a parent.

Works like class_traits, except for excluding traits from parents.

class_print_help(inst=None)

Get the help string for a single trait and print it.

class_trait_names(**metadata)

Get a list of all the names of this class’ traits.

This method is just like the trait_names() method, but is unbound.

class_traits(**metadata)

Get a dict of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.

This method is just like the traits() method, but is unbound.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.

clear_instance()

unset _instance for this class and singleton parents.

clear_output(wait=False)
clear_request(stream, idents, parent)

Clear our namespace.

comm_info_request(stream, ident, parent)
complete_request(stream, ident, parent)
config

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

connect_request(stream, ident, parent)
control_msg_types = ['execute_request', 'complete_request', 'inspect_request', 'history_request', 'comm_info_request', 'kernel_info_request', 'connect_request', 'shutdown_request', 'is_complete_request', 'apply_request', 'clear_request', 'abort_request']
control_stream

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

cross_validation_lock

A contextmanager for running a block with our cross validation lock set to True.

At the end of the block, the lock’s value is restored to its value prior to entering the block.

dispatch_control(msg)

dispatch control requests

dispatch_shell(stream, msg)

dispatch shell requests

do_apply(content, bufs, msg_id, reply_metadata)
do_clear()
do_complete(code, cursor_pos)
do_execute(code, silent=False, store_history=True, user_expressions=None, allow_stdin=False)
do_execute_direct(code: str, silent: bool = False) → str

This is the main method that takes code from the Jupyter cell and submits it to the SAS server

Parameters:
  • code – code from the cell
  • silent
Returns:

str with either the log or list

do_execute_file(filename)

Default code for running a file. Just opens the file, and sends the text to do_execute_direct.

do_execute_meta(code)

Execute meta code in the kernel. This uses the execute infrastructure but allows JavaScript to talk directly to the kernel bypassing normal processing.

When responding to the %%debug magic, the step and reset meta commands can answer with a string in the format:

“highlight: [start_line, start_col, end_line, end_col]”

for highlighting expressions in the frontend.

do_function_direct(function_name, arg)

Call a function in the kernel language with args (as a single item).

do_history(hist_access_type, output, raw, session=None, start=None, stop=None, n=None, pattern=None, unique=False)

Access history at startup.

do_inspect(code, cursor_pos, detail_level=0)
do_is_complete(code)

Given code as string, returns dictionary with ‘status’ representing whether code is ready to evaluate. Possible values for status are:

‘complete’ - ready to evaluate ‘incomplete’ - not yet ready ‘invalid’ - invalid code ‘unknown’ - unknown; the default unless overridden

Optionally, if ‘status’ is ‘incomplete’, you may indicate an indentation string.

Example:

return {‘status’
: ‘incomplete’,
‘indent’: ‘ ‘ * 4}
do_one_iteration()

step eventloop just once

do_shutdown(restart)

Shut down the app gracefully, saving history.

enter_eventloop()

enter eventloop

eventloop

A trait which allows any value.

execute_request(stream, ident, parent)

handle an execute_request

execution_count = 0
finish_metadata(parent, metadata, reply_content)

Finish populating metadata.

Run after completing an execution request.

func_call_regex = '([^\\d\\W][\\w\\.]*)\\([^\\)\\()]*\\Z'
get_completions(info)

Get completions from kernel for procs and statements.

get_help_on(expr, level=0, none_on_fail=False, cursor_pos=-1)
get_kernel_help_on(info, level=0, none_on_fail=False)
get_local_magics_dir()

Returns the path to local magics dir (eg ~/.ipython/metakernel/magics)

get_magic(text)
get_magic_args(text)
get_usage()
get_variable(name)

Lookup a variable name and return a Python-typed value.

getpass(prompt='', stream=None)

Forward getpass to frontends

Raises:StdinNotImplentedError if active frontend doesn’t support stdin.
handle_plot_settings()

Handle the current plot settings

has_trait(name)

Returns True if the object has a trait with the specified name.

help_suffix = '?'
history_request(stream, ident, parent)
hold_trait_notifications()

Context manager for bundling trait change notifications and cross validation.

Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.

ident

A trait for unicode strings.

identifier_regex = '[^\\d\\W][\\w\\.]*'
implementation = 'sas_kernel'
implementation_version = '2.1.0'
init_metadata(parent)

Initialize metadata.

Run at the beginning of execution requests.

initialize_debug(code)

SAS does not have formal debug tools from this interface

initialized()

Has an instance been created?

inspect_request(stream, ident, parent)
instance(*args, **kwargs)

Returns a global instance of this class.

This method create a new instance if none have previously been created and returns a previously created instance is one already exists.

The arguments and keyword arguments passed to this method are passed on to the __init__() method of the class upon instantiation.

Examples

Create a singleton class using instance, and retrieve it:

>>> from traitlets.config.configurable import SingletonConfigurable
>>> class Foo(SingletonConfigurable): pass
>>> foo = Foo.instance()
>>> foo == Foo.instance()
True

Create a subclass that is retrived using the base class instance:

>>> class Bar(SingletonConfigurable): pass
>>> class Bam(Bar): pass
>>> bam = Bam.instance()
>>> bam == Bar.instance()
True
int_id

An int trait.

iopub_socket

A trait which allows any value.

iopub_thread

A trait which allows any value.

is_complete_request(stream, ident, parent)
kernel_info
kernel_info_request(stream, ident, parent)
language = 'sas'
language_info = {'name': 'sas', 'mimetype': 'text/x-sas', 'codemirror_mode': 'sas', 'file_extension': '.sas'}
language_version = ('9.4+',)
log

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

magic_prefixes = {'magic': '%', 'shell': '!', 'help': '?'}
makeSubkernel(kernel)

Run this method in an IPython kernel to set this kernel’s input/output settings.

meta_kernel = None
msg_types = ['execute_request', 'complete_request', 'inspect_request', 'history_request', 'comm_info_request', 'kernel_info_request', 'connect_request', 'shutdown_request', 'is_complete_request', 'apply_request']
notify_change(change)
observe(handler, names=traitlets.All, type='change')

Setup a handler to be called when a trait changes.

This is used to setup dynamic notifications of trait changes.

Parameters:

handler : callable

A callable that is called when a trait changes. Its signature should be handler(change), where change is a dictionary. The change dictionary at least holds a ‘type’ key. * type: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: * owner : the HasTraits instance * old : the old value of the modified trait attribute * new : the new value of the modified trait attribute * name : the name of the modified trait attribute.

names : list, str, All

If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

type : str, All (default: ‘change’)

The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.

on_trait_change(handler=None, name=None, remove=False)

DEPRECATED: Setup a handler to be called when a trait changes.

This is used to setup dynamic notifications of trait changes.

Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).

If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.

Parameters:

handler : callable, None

A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).

name : list, str, None

If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

remove : bool

If False (the default), then install the handler. If True then unintall it.

parent

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

parse_code(code, cursor_start=0, cursor_end=-1)
post_execute(retval, code, silent)
post_handler_hook()

Hook to execute after calling message handler

pre_handler_hook()

Hook to execute before calling message handler

profile_dir

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

raw_input(prompt='')

Forward raw_input to frontends

Raises:StdinNotImplentedError if active frontend doesn’t support stdin.
record_ports(ports)

Record the ports that this kernel is using.

The creator of the Kernel instance must call this methods if they want the connect_request() method to return the port numbers.

register_magics(magic_klass)
reload_magics()
repr(item)
restart_kernel()

Restart the kernel

run_as_main()

Launch or install a metakernel.

Modules implementing a metakernel subclass can use the following lines:

if __name__ == ‘__main__’:
MetaKernelSubclass.run_as_main()
section_names()

return section names as a list

send_response(stream, msg_or_type, content=None, ident=None, buffers=None, track=False, header=None, metadata=None)

Send a response to the message we’re currently processing.

This accepts all the parameters of jupyter_client.session.Session.send() except parent.

This relies on set_parent() having been called for the current message.

session

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

set_parent(ident, parent)

Set the current parent_header

Side effects (IOPub messages) and replies are associated with the request that caused them via the parent_header.

The parent identity is used to route input_request messages on the stdin channel.

set_trait(name, value)

Forcibly sets trait attribute, including read-only attributes.

set_variable(name, value)

Set a variable to a Python-typed value.

setup_instance(*args, **kwargs)
shell_streams

An instance of a Python list.

should_handle(stream, msg, idents)

Check whether a shell-channel message should be handled

Allows subclasses to prevent handling of certain messages (e.g. aborted requests).

shutdown_request(stream, ident, parent)
start()

register dispatchers for streams

stdin_socket

A trait which allows any value.

trait_events(name=None)

Get a dict of all the event handlers of this class.

Parameters:

name: str (default: None)

The name of a trait of this class. If name is None then all the event handlers of this class will be returned instead.

Returns:

The event handlers associated with a trait name, or all event handlers.

trait_metadata(traitname, key, default=None)

Get metadata values for trait by key.

trait_names(**metadata)

Get a list of all the names of this class’ traits.

traits(**metadata)

Get a dict of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.

unobserve(handler, names=traitlets.All, type='change')

Remove a trait change handler.

This is used to unregister handlers to trait change notifications.

Parameters:

handler : callable

The callable called when a trait attribute changes.

names : list, str, All (default: All)

The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.

type : str or All (default: ‘change’)

The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.

unobserve_all(name=traitlets.All)

Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.

update_config(config)

Update config and load the new values

SAS Kernel Object

class sas_kernel.kernel.SASKernel(**kwargs)

Bases: metakernel._metakernel.MetaKernel

SAS Kernel for Jupyter implementation. This module relies on SASPy

do_execute_direct(code: str, silent: bool = False) → str

This is the main method that takes code from the Jupyter cell and submits it to the SAS server

Parameters:
  • code – code from the cell
  • silent
Returns:

str with either the log or list

do_shutdown(restart)

Shut down the app gracefully, saving history.

get_completions(info)

Get completions from kernel for procs and statements.

initialize_debug(code)

SAS does not have formal debug tools from this interface