Skip to content
Snippets Groups Projects
README.md 927 B
Newer Older
[![Build Status](https://travis-ci.org/avakar/pytoml.svg?branch=master)](https://travis-ci.org/avakar/pytoml)

Martin Vejnár's avatar
Martin Vejnár committed
# pytoml

Martin Vejnár's avatar
Martin Vejnár committed
This project aims at being a specs-conforming and strict parser and writer for [TOML][1] files.
The library currently supports [version 0.4.0][2] of the specs and runs with Python 2.7 and 3.4+.
Martin Vejnár's avatar
Martin Vejnár committed

Install:

    pip install pytoml
Martin Vejnár's avatar
Martin Vejnár committed

The interface is the same as for the standard `json` package.

    >>> import pytoml as toml
    >>> toml.loads('a = 1')
    {'a': 1}
    >>> with open('file.toml', 'rb') as fin:
Martin Vejnár's avatar
Martin Vejnár committed
    ...     obj = toml.load(fin)
    >>> obj
Martin Vejnár's avatar
Martin Vejnár committed
    {'a': 1}

The `loads` function accepts either a bytes object
(that gets decoded as UTF-8 with no BOM allowed),
or a unicode object.

Martin Vejnár's avatar
Martin Vejnár committed
Use `dump` or `dumps` to serialize a dict into TOML.

    >>> print toml.dumps(obj)
    a = 1

Martin Vejnár's avatar
Martin Vejnár committed
  [1]: https://github.com/toml-lang/toml
  [2]: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md