Function Repository Resource:

ExportYAML

Source Notebook

Export an expression as a YAML file

Contributed by: Arnoud Buzing

ResourceFunction["ExportYAML"][session,assoc,file]

exports assoc to a YAML file using a Python session.

Details and Options

YAML refers to YAML Ain't Markup Language and is a human-friendly data serialization standard for all programming languages.
ResourceFunction["ExportYAML"] requires the PyYAML package to be installed on your machine. This package can be installed by running the command pip install PyYAML.

Examples

Basic Examples (3) 

Start a Python session:

In[1]:=
session = StartExternalSession["Python"];

Export an association as a YAML file:

In[2]:=
ResourceFunction["ExportYAML"][session, <|
  "scalar" -> 5,
  "alias" -> 5,
  "sequence" -> {1, 2, 3},
  "mapping" -> {<|1 -> "one"|>, <|2 -> "two"|>, <|3 -> "three"|>}|>, "C:\\Users\\arnoudb.WRI\\out.yaml"]

Print the resulting file for visual inspection:

In[3]:=
FilePrint["C:\\Users\\arnoudb.WRI\\out.yaml"]

Publisher

Arnoud Buzing

Version History

  • 1.0.0 – 10 July 2019

Related Resources

License Information