Skip to main content

A lightweight YAML Parser for Python

Project description

PyPI Package PyPI Python Versions PyPI Package License See Build Status on Travis CI

A lightweight YAML Parser for Python

Please note that Poyo supports only a chosen subset of the YAML format.

It can only read but not write and is not compatible with JSON.

Poyo does not allow deserialization of arbitrary Python objects. Supported types are str, bool, int, float, NoneType as well as dict and list values. Please see the examples below to get an idea of what Poyo understands.


poyo is available for download from PyPI via pip:

$ pip install poyo

Poyo is 100% Python and does not require any additional libs.


Poyo comes with a parse_string() function, to load utf-8 encoded string data into a Python dict.

import codecs
import logging

from poyo import parse_string, PoyoException


with'tests/foobar.yml', encoding='utf-8') as ymlfile:
    ymlstring =

    config = parse_string(ymlstring)
except PoyoException as exc:


In (YAML):

default_context: # foobar
    greeting: こんにちは
    email: ""
    docs: true

    gui: FALSE
    123: 456.789
    # comment
    # allthethings
    'some:int': 1000000
    foo: "hallo #welt" #Inline comment :)
    trueish: Falseeeeeee
    relative-root: /          # web app root path (default: '')
    lektor:      # local build
        # docs or didn't happen
        -    mkdocs
        - 'sphinx'

        - null
    # 今日は
zZz: True
NullValue: Null

# Block
# Comment

Hello World:
    # See you at EuroPython
    null: This is madness   # yo
"Yay #python": Cool!

Out (Python):

    u'default_context': {
        u'greeting': u'こんにちは',
        u'email': u'',
        u'docs': True,
        u'gui': False,
        u'lektor': '',
        u'relative-root': '/',
        123: 456.789,
        u'some:int': 1000000,
        u'foo': u'hallo #welt',
        u'trueish': u'Falseeeeeee',
        u'doc_tools': [u'mkdocs', u'sphinx', None],
    u'zZz': True,
    u'NullValue': None,
    u'Hello World': {
        None: u'This is madness',
        u'gh': u'{0}.git',
    u'Yay #python': u'Cool!'


Poyo follows the recommendations for logging in a library, which means it does not configure logging itself. Its root logger is named poyo and the names of all its children loggers track the package/module hierarchy. Poyo logs to a NullHandler and solely on DEBUG level.

If your application configures logging and allows debug messages to be shown, you will see logging when using Poyo. The log messages indicate which parser method is used for a given string as the parser deseralizes the config. You can remove all logging from Poyo in your application by setting the log level of the poyo logger to a value higher than DEBUG.

Disable Logging:

import logging


Example Debug Logging Config:

import logging
from poyo import parse_string


CONFIG = """
default_context: # foobar
    greeting: こんにちは
    gui: FALSE
        # docs or didn't happen
        -    mkdocs
        - 'sphinx'
    123: 456.789


Example Debug Logging Messages:

DEBUG:poyo.parser:parse_blankline <- \n
DEBUG:poyo.parser:parse_blankline -> IGNORED
DEBUG:poyo.parser:parse_dashes <- ---\n
DEBUG:poyo.parser:parse_dashes -> IGNORED
DEBUG:poyo.parser:parse_section <- default_context: # foobar\n
DEBUG:poyo.parser:parse_str <- default_context
DEBUG:poyo.parser:parse_str -> default_context
DEBUG:poyo.parser:parse_section -> <Section name: default_context>
DEBUG:poyo.parser:parse_simple <-     greeting: \u3053\u3093\u306b\u3061\u306f\n
DEBUG:poyo.parser:parse_str <- greeting
DEBUG:poyo.parser:parse_str -> greeting
DEBUG:poyo.parser:parse_str <- \u3053\u3093\u306b\u3061\u306f
DEBUG:poyo.parser:parse_str -> \u3053\u3093\u306b\u3061\u306f
DEBUG:poyo.parser:parse_simple -> <Simple name: greeting, value: \u3053\u3093\u306b\u3061\u306f>
DEBUG:poyo.parser:parse_simple <-     gui: FALSE\n
DEBUG:poyo.parser:parse_str <- gui
DEBUG:poyo.parser:parse_str -> gui
DEBUG:poyo.parser:parse_false <- FALSE
DEBUG:poyo.parser:parse_false -> False
DEBUG:poyo.parser:parse_simple -> <Simple name: gui, value: False>
DEBUG:poyo.parser:parse_list <-     doc_tools:\n        # docs or didn't happen\n        -    mkdocs\n        - 'sphinx'\n
DEBUG:poyo.parser:parse_str <- mkdocs
DEBUG:poyo.parser:parse_str -> mkdocs
DEBUG:poyo.parser:parse_str <- 'sphinx'
DEBUG:poyo.parser:parse_str -> sphinx
DEBUG:poyo.parser:parse_str <- doc_tools
DEBUG:poyo.parser:parse_str -> doc_tools
DEBUG:poyo.parser:parse_list -> <Simple name: doc_tools, value: ['mkdocs', 'sphinx']>
DEBUG:poyo.parser:parse_simple <-     123: 456.789\n
DEBUG:poyo.parser:parse_int <- 123
DEBUG:poyo.parser:parse_int -> 123
DEBUG:poyo.parser:parse_float <- 456.789
DEBUG:poyo.parser:parse_float -> 456.789
DEBUG:poyo.parser:parse_simple -> <Simple name: 123, value: 456.789>
DEBUG:poyo.parser:parse_simple <-     docs: true\n
DEBUG:poyo.parser:parse_str <- docs
DEBUG:poyo.parser:parse_str -> docs
DEBUG:poyo.parser:parse_true <- true
DEBUG:poyo.parser:parse_true -> True
DEBUG:poyo.parser:parse_simple -> <Simple name: docs, value: True>
DEBUG:root:{'default_context': {'docs': True, 'doc_tools': ['mkdocs', 'sphinx'], 123: 456.789, 'greeting': 'こんにちは', 'gui': False}}


Because a couple of cookiecutter users, including myself, ran into issues when installing well-known YAML parsers for Python on various platforms and Python versions.


If you encounter any problems, please file an issue along with a detailed description.

Code of Conduct

Everyone interacting in the Poyo project’s codebases, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.


Distributed under the terms of the MIT license, poyo is free and open source software.

OSI certified

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
poyo-0.4.2-py2.py3-none-any.whl (8.8 kB) Copy SHA256 hash SHA256 Wheel py2.py3
poyo-0.4.2.tar.gz (15.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page