pyYaml dump options

Using pyYaml to create input file for a small db migration project, I did not found any place describing the exhaustive list of keyword attributes that yaml.dump method accepts. Here is a first guess :

I found some information in the file of python-yaml. Some of them are described on the PyYAML documentation page ( I’m not a YAML expert thus, please comment to correct misunderstandings or errors in my description.

Valid keywords for the method def dump(data, stream=None, Dumper=Dumper, **kwds) in python-yaml :

default_style : indicates the style of the scalar. Possible values are None, '', '\'', '"', '|', '>'.

default_flow_style :  indicates if a collection is block or flow. The possible values are None, True, False.

canonical : if True export tag type to the output file

indent :  sets the preferred indentation

width : set the preferred line width
allow_unicode : allow unicode in output file

line_break : specify the line break you need

encoding : output encoding, defaults to utf-8

explicit_start : if True, adds an explicit start using “—”

explicit_end: if True, adds an explicit end using “—”

version : version of the YAML parser, tuple (major, minor), supports only major version 1

tags : I didn’t find any information about this parameter … and no time to test it ;-). Comments are welcome !


4 Responses to pyYaml dump options

  1. Will says:

    Yeah, got the same problem. Big documentation, but no informations >.<

  2. Hey, thanks for taking the time to write this down — it was enough for me to figure out that setting default_flow_style = False will cause each field to go on a separate line, as I needed.

  3. D says:

    More undocumented surprises…
    By default yaml.load will resolve any of these as booleans!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: