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

Install

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

pip install yamlmagic

Enable

Ad-hoc

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

%reload_ext yamlmagic

Configuration

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

c.InteractiveShellApp.extensions = ['yaml_magic']

Use

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

%%yaml
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>
x
[{'a': 1, 'b': 2}]

By default, yaml.SafeLoader will be used, which won’t allow the powerful but dangerous (and unportable) `!python/ tags <http://pyyaml.org/wiki/PyYAMLDocumentation#YAMLtagsandPythontypes>`__. 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
    pass
%%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}]

Contribute

Issues and pull requests welcome!

License

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

Thank

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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

Details for the file yamlmagic-0.2.0.tar.gz.

File metadata

  • Download URL: yamlmagic-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yamlmagic-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9a64977dd3f379530127a74a35dfc5b1a5ac82efb9a36d87a182d0c650a7205
MD5 ae27c95eaa433014e58155bb5ad0af92
BLAKE2b-256 19796f0f00b6ff87bb9c2a1227adef728293770c8161e8141101b8faf8b4e344

See more details on using hashes here.

File details

Details for the file yamlmagic-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for yamlmagic-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a2d405f613b3bdd8004355cb242092a840f2a24a26db1cdbcc867e2004a80d03
MD5 159290bdaab6734555489dd9f397ad21
BLAKE2b-256 bddbd677d565b9048b9003ae6aac3ec34cce9dcc0e9c13bd68289c7c8dde3959

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page