Skip to main content

a YAML magic for IPython notebooks

Project description

an IPython magic for capturing data in YAML into a running IPython kernel.

Build Status pypi


From the command line (or with ! in a notebook cell):

pip install yamlmagic



In the notebook, you can use the %load_ext or %reload_ext line magic.

%reload_ext yamlmagic


In your profile’s, you can add the following line to automatically load yamlmagic into all your running kernels:

c.InteractiveShellApp.extensions = ['yaml_magic']


The %%yaml cell magic will either act as simple parser:

a_toplevel_key: 1
<IPython.core.display.Javascript object>
{'a_toplevel_key': 1}

which can be accessed by the special last result variable _:

{'a_toplevel_key': 1}

Or will update a named variable with the parsed document:

%%yaml x
- a: 1
  b: 2
<IPython.core.display.Javascript object>
[{'a': 1, 'b': 2}]

By default, yaml.SafeLoader will be used, which won’t allow the powerful but dangerous (and unportable) `!python/ tags <>`__. If you’d like to use them, provide the -l (or --loader) argument with a BaseLoader subclass available via a local variable…

from yaml import Loader
class FooLoader(Loader):
    # some special things you have built
%%yaml --loader FooLoader
- a: !!python/float 1
  b: !!python/float 2
<IPython.core.display.Javascript object>
[{'a': 1.0, 'b': 2.0}]

…or dotted-notation path to a loader:

%%yaml --loader yaml.Loader
- a: !!python/float 1
  b: !!python/float 2
<IPython.core.display.Javascript object>
[{'a': 1.0, 'b': 2.0}]


Issues and pull requests welcome!


yamlmagic is released as free software under the BSD 3-Clause license.


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamlmagic-0.2.0.tar.gz (7.0 kB view hashes)

Uploaded source

Built Distribution

yamlmagic-0.2.0-py2.py3-none-any.whl (5.5 kB view hashes)

Uploaded 3 4

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page