A lightweight YAML Parser for Python. 🐓
Likely abandoned. No release or commit for years (last release over 7 years ago).
pip install poyopoyo
A lightweight YAML Parser for Python. 🐓
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 note that poyo supports only a chosen subset of the YAML format that is required to parse cookiecutter user configuration files. poyo does not have support for serializing into YAML and is not compatible with JSON.
Installation
poyo is available on PyPI for Python versions 2.7 and newer and can be installed with pip:
pip install poyo
This package does not have any additional requirements. 📦
Usage
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
logging.basicConfig(level=logging.DEBUG)
with codecs.open("tests/foobar.yml", encoding="utf-8") as ymlfile:
ymlstring = ymlfile.read()
try:
config = parse_string(ymlstring)
except PoyoException as exc:
logging.error(exc)
else:
logging.debug(config)
Example
Input YAML string
---
default_context: # foobar
greeting: こんにちは
email: "raphael@hackebrot.de"
docs: true
gui: FALSE
123: 456.789
# comment
# allthethings
'some:int': 1000000
foo: "hallo #welt" #Inline comment :)
longtext: >
This is a multiline string.
It can contain all manners of characters.
Single line breaks are ignored,
but blank linkes cause line breaks.
trueish: Falseeeeeee
blog : raphael.codes
relative-root: / # web app root path (default: '')
lektor: 0.0.0.0:5000 # local build
doc_tools:
# 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
gh: https://github.com/{0}.git
"Yay #python": Cool!
Output Python dict
{
u"default_context": {
u"greeting": u"こんにちは",
u"email": u"raphael@hackebrot.de",
u"docs": True,
u"gui": False,
u"lektor": "0.0.0.0:5000",
u"relative-root": "/",
123: 456.789,
u"some:int": 1000000,
u"foo": u"hallo #welt",
u"longtext": (
u"This is a multiline string. It can contain all "
u"manners of characters.\nSingle line breaks are "
u"ignored, but blank linkes cause line breaks.\n"
),
u"trueish": u"Falseeeeeee",
u"blog": u"raphael.codes",
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"https://github.com/{0}.git",
},
u"Yay #python": u"Cool!",
}