Caller Class§

See API documentation for Caller.

[1]:
import magic_call

Defining Commands§

[2]:
commands = [
    ('svg', 'dot -Tsvg -o {}.svg'),
]
[3]:
mycaller = magic_call.Caller(commands)

Returning Raw Data§

[4]:
blobs = mycaller.call('digraph { a -> b }', formats=['svg'])

A list of formats produces a list of data blobs.

[5]:
svg_blob, = blobs
[6]:
from IPython.display import SVG
[7]:
SVG(svg_blob)
[7]:
../_images/base_caller_11_0.svg

Creating Files§

[8]:
files = mycaller.call('digraph { a -> b }', files=['delme-caller.svg'])
files
[8]:
[PosixPath('delme-caller.svg')]

The file delme-caller.svg has been created:

example image

[9]:
file, = files
[10]:
SVG(filename=file)
[10]:
../_images/base_caller_16_0.svg

Both at the Same Time§

A tuple of lists is returned.

[11]:
(blob2,), (file2,) = mycaller.call(
    'digraph { a -> b }',
    formats=['svg'],
    files=['delme-caller2.svg'])

The file delme-caller2.svg has been created:

another example image

Non-Blocking Calls§

If you specify blocking=False, a future will be returned for each output.

[12]:
futures = mycaller.call('digraph { a -> b }', formats=['svg'], blocking=False)
futures
[12]:
[<Future at 0x7f7be8fe1750 state=pending>]
[13]:
svg_future, = futures

You can check whether the result is still being worked on:

[14]:
svg_future.done()
[14]:
False

To obtain the actual result, call result() on the future object.

If the result is already finished at this time, the method returns it immediately. If not, the call blocks until the result is available.

A timeout can be specified if desired.

[15]:
SVG(svg_future.result())
[15]:
../_images/base_caller_26_0.svg

Of course, files can be created similarly in a non-blocking way.