PythonContext

class stencila.PythonContext(*args, **kwargs)[source]
libraries(*args)[source]
list(types=[])[source]
compile(cell)[source]

Compile a cell

Returns:A compiled cell
compile_func(func=None, file=None, dir=None)[source]

Compile a func operation

Parses the source of the function (either a string or a file path) to extract it’s description, param, return etc properties.

>>> context.compile_func({
>>>     'type': 'func',
>>>     'source': 'def hello(who): return "Hello Hello %s!" % who'
>>> })
{
    'type': 'func',
    'name': 'hello',
    'source': 'def hello(): return "Hello Hello %s!" % who'
    'params': [{
        'name': 'who'
    }],
    ...
}
Parameters:func (dict or string) – A func operation. If a string is supplied then an operation object is created with the source property set to the string.
Returns:
  • func (dict) – The compiled func operation
  • messages (list) – A list of messages (e.g errors)
execute(cell)[source]
spec = {'client': 'ContextHttpClient', 'name': 'PythonContext'}