wiki:PyYAML

Version 20 (modified by xi, 7 years ago) (diff)

The release 3.05

PyYAML

PyYAML is a YAML parser and emitter for Python.

Overview

 YAML is a data serialization format designed for human readability and interaction with scripting languages.

PyYAML is a YAML parser and emitter for the Python programming language.

PyYAML features

  • a complete  YAML 1.1 parser. In particular, PyYAML can parse all examples from the specification. The parsing algorithm is simple enough to be a reference for YAML parser implementors.
  • Unicode support including UTF-8/UTF-16 input/output and \u escape sequences.
  • low-level event-based parser and emitter API (like SAX).
  • high-level API for serializing and deserializing native Python objects (like DOM or pickle).
  • support for all types from the  YAML types repository. A simple extension API is provided.
  • relatively sensible error messages.

Note that PyYAML is still young and may have some bugs. Furthermore, PyYAML is written in Python and is slow comparing to C based parsers.

Requirements

PyYAML requires Python 2.3 or higher.

Download and Installation

The current stable release of PyYAML: 3.05.

Download links:

Unpack the archive and install the package by executing

$ python setup.py install

If you want to use LibYAML bindings, you need to download and install LibYAML and  Pyrex. Then you may install the bindings by executing

$ python setup_with_libyaml.py install

You may check out the latest development code of PyYAML from the Subversion repository  http://svn.pyyaml.org/pyyaml/trunk

$ svn checkout http://svn.pyyaml.org/pyyaml/trunk pyyaml-trunk

Documentation

Quick example:

>>> import yaml

>>> print yaml.load("""
... name: Vorlin Laruknuzum
... sex: Male
... class: Priest
... title: Acolyte
... hp: [32, 71]
... sp: [1, 13]
... gold: 423
... inventory:
... - a Holy Book of Prayers (Words of Wisdom)
... - an Azure Potion of Cure Light Wounds
... - a Siver Wand of Wonder
... """)

{'name': 'Vorlin Laruknuzum', 'gold': 423, 'title': 'Acolyte', 'hp': [32, 71],
'sp': [1, 13], 'sex': 'Male', 'inventory': ['a Holy Book of Prayers (Words of Wisdom)',
'an Azure Potion of Cure Light Wounds', 'a Siver Wand of Wonder'], 'class': 'Priest'}

>>> print yaml.dump({'name': "The Cloak 'Colluin'", 'depth': 5, 'rarity': 45,
... 'weight': 10, 'cost': 50000, 'flags': ['INT', 'WIS', 'SPEED', 'STEALTH']})

name: The Cloak 'Colluin'
rarity: 45
flags: [INT, WIS, SPEED, STEALTH]
weight: 10
cost: 50000
depth: 5

For more details, please check PyYAML Documentation.

History

3.05 (2007-05-13)

  • Allow for immutable subclasses of YAMLObject. Fixed #53.
  • Make the encoding of the unicode->str conversion explicit; fixed #52.
  • Fixed a problem when the DOCUMENT-END event is not emitted until the beginning of the next document is available. Fixed #51. Thanks edward(at)sweetbytes.net for the bug report.
  • Improve output of float values. Fixed #49.
  • Fix the bug when the path in add_path_resolver contains boolean values. Fixed #43 (thanks to jstroud(at)mbi.ucla.edu for reporting and pointing to the cause).
  • Use the types module instead of constructing type objects by hand. Fixed #41. Thanks to v.haisman(at)sh.cvut.cz for the patch.
  • Fix loss of microsecond precision in datetime.datetime constructor (fix #30). Thanks to edemaine(at)mit.edu for the bug report and the patch.
  • Fixed loading an empty YAML stream.

3.04 (2006-08-20)

  • Include experimental LibYAML bindings.
  • Fully support recursive structures (close #5).
  • Sort dictionary keys (close #23). Mapping node values are now represented as lists of pairs instead of dictionaries. Do not check for duplicate mapping keys as it didn't work correctly anyway.
  • Fix invalid output of single-quoted scalars in cases when a single quote is not escaped when preceeded by whitespaces or line breaks (close #17).
  • To make porting easier, rewrite Parser not using generators.
  • Fix handling of unexpected block mapping values, like
    : foo
    
  • Fix a bug in Representer.represent_object: copy_reg.dispatch_table was not correctly handled.
  • Fix a bug when a block scalar is incorrectly emitted in the simple key context.
  • Hold references to the objects being represented (close #22).
  • Make Representer not try to guess !!pairs when a list is represented.
  • Fix timestamp constructing and representing (close #25).
  • Fix the 'N' plain scalar being incorrectly recognized as !!bool (close #26).

3.03 (2006-06-19)

  • Fix Python 2.5 compatibility issues.
  • Fix numerous bugs in the float handling.
  • Fix scanning some ill-formed documents.
  • Other minor fixes.

3.02 (2006-05-15)

  • Fix win32 installer. Apparently bdist_wininst does not work well under Linux.
  • Fix a bug in add_path_resolver.
  • Add the yaml-highlight example. Try to run on a color terminal: python yaml_hl.py <any_document.yaml.

3.01 (2006-05-07)

  • Initial release. The version number reflects the codename of the project (PyYAML 3000) and differenciates it from the abandoned PyYaml module.

Development and bug reports

You may check out the PyYAML source code from  PyYAML SVN repository.

If you find a bug in PyYAML, please file a bug report. You may review open bugs through the list of open tickets.

You may discuss PyYAML at  the YAML-core mailing list.

Author and copyright

The PyYAML module is written by Kirill Simonov.

PyYAML is released under the MIT license.