poyo


Namepoyo JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/hackebrot/poyo
SummaryA lightweight YAML Parser for Python. ๐Ÿ“
upload_time2019-07-26 12:51:04
maintainerRaphael Pierzina
docs_urlNone
authorRaphael Pierzina
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
licenseMIT
keywords yaml parser cookiecutter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # poyo

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][cookiecutterrc]. poyo does not have support for serializing into YAML
and is not compatible with JSON.

[cookiecutterrc]: https://cookiecutter.readthedocs.io/en/latest/advanced/user_config.html

## Installation

poyo is available on [PyPI][PyPI] for Python versions 2.7 and newer and can
be installed with [pip][pip]:

```text
pip install poyo
```

[PyPI]: https://pypi.org/project/poyo/
[pip]: https://pypi.org/project/pip/

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.

```python
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

```yaml
---
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

```python
{
    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!",
}
```

## Logging

poyo follows the recommendations for [logging in a library][logging], 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``.

[logging]: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

### Disable Logging

```python
import logging

logging.getLogger("poyo").setLevel(logging.WARNING)
```

### Example Debug Logging Config

```python
import logging
from poyo import parse_string

logging.basicConfig(level=logging.DEBUG)

CONFIG = """
---
default_context: # foobar
    greeting: ใ“ใ‚“ใซใกใฏ
    gui: FALSE
    doc_tools:
        # docs or didn't happen
        -    mkdocs
        - 'sphinx'
    123: 456.789
"""

parse_string(CONFIG)
```

### Example Debug Logging Messages

```text
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>
```

## About this project

We created this project to work around installation issues with a
[cookiecutter][cookiecutter] version that depended on existing YAML parsers
for Python. For more information please check out this [GitHub issue][issue].

[issue]: https://github.com/cookiecutter/cookiecutter/pull/621

## Community

Would you like to contribute to **poyo**? You're awesome! ๐Ÿ˜ƒ

Please check out the [good first issue][good first issue] label for tasks,
that are good candidates for your first contribution to poyo. Your
contributions are greatly appreciated! Every little bit helps and credit will
always be given.

Everyone interacting in the poyo project's codebases, issue trackers, chat
rooms, and mailing lists is expected to follow the [PyPI Code of
Conduct][code of conduct].

Join the poyo [community][community]! ๐ŸŒ๐ŸŒ๐ŸŒŽ

[code of conduct]: https://www.pypa.io/en/latest/code-of-conduct/
[community]: https://github.com/hackebrot/poyo/blob/master/COMMUNITY.md
[good first issue]: https://github.com/hackebrot/poyo/labels/good%20first%20issue

## License

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

[MIT]: https://github.com/hackebrot/poyo/blob/master/LICENSE

[cookiecutter]: https://github.com/cookiecutter/cookiecutter



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hackebrot/poyo",
    "name": "poyo",
    "maintainer": "Raphael Pierzina",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
    "maintainer_email": "raphael@hackebrot.de",
    "keywords": "YAML,parser,cookiecutter",
    "author": "Raphael Pierzina",
    "author_email": "raphael@hackebrot.de",
    "download_url": "https://files.pythonhosted.org/packages/7d/56/01b496f36bbd496aed9351dd1b06cf57fd2f5028480a87adbcf7a4ff1f65/poyo-0.5.0.tar.gz",
    "platform": "",
    "description": "# poyo\n\nA lightweight YAML Parser for Python. \ud83d\udc13\n\n**poyo** does not allow deserialization of arbitrary Python objects. Supported\ntypes are `str`, `bool`, `int`, `float`, `NoneType` as well as `dict` and\n`list` values.\n\n\u26a0\ufe0f Please note that poyo supports only a chosen subset of the YAML format\nthat is required to parse [cookiecutter user configuration\nfiles][cookiecutterrc]. poyo does not have support for serializing into YAML\nand is not compatible with JSON.\n\n[cookiecutterrc]: https://cookiecutter.readthedocs.io/en/latest/advanced/user_config.html\n\n## Installation\n\npoyo is available on [PyPI][PyPI] for Python versions 2.7 and newer and can\nbe installed with [pip][pip]:\n\n```text\npip install poyo\n```\n\n[PyPI]: https://pypi.org/project/poyo/\n[pip]: https://pypi.org/project/pip/\n\nThis package does not have any additional requirements. \ud83d\udce6\n\n## Usage\n\npoyo comes with a ``parse_string()`` function, to load utf-8 encoded string\ndata into a Python dict.\n\n```python\nimport codecs\nimport logging\n\nfrom poyo import parse_string, PoyoException\n\nlogging.basicConfig(level=logging.DEBUG)\n\nwith codecs.open(\"tests/foobar.yml\", encoding=\"utf-8\") as ymlfile:\n    ymlstring = ymlfile.read()\n\ntry:\n    config = parse_string(ymlstring)\nexcept PoyoException as exc:\n    logging.error(exc)\nelse:\n    logging.debug(config)\n```\n\n## Example\n\n### Input YAML string\n\n```yaml\n---\ndefault_context: # foobar\n    greeting: \u3053\u3093\u306b\u3061\u306f\n    email: \"raphael@hackebrot.de\"\n    docs: true\n\n    gui: FALSE\n    123: 456.789\n    # comment\n    # allthethings\n    'some:int': 1000000\n    foo: \"hallo #welt\" #Inline comment :)\n    longtext: >\n        This is a multiline string.\n        It can contain all manners of characters.\n\n        Single line breaks are ignored,\n        but blank linkes cause line breaks.\n    trueish: Falseeeeeee\n    blog   : raphael.codes\n    relative-root: /          # web app root path (default: '')\n    lektor: 0.0.0.0:5000      # local build\n    doc_tools:\n        # docs or didn't happen\n        -    mkdocs\n        - 'sphinx'\n\n        - null\n    # \u4eca\u65e5\u306f\nzZz: True\nNullValue: Null\n\n# Block\n# Comment\n\nHello World:\n    # See you at EuroPython\n    null: This is madness   # yo\n    gh: https://github.com/{0}.git\n\"Yay #python\": Cool!\n```\n\n### Output Python dict\n\n```python\n{\n    u\"default_context\": {\n        u\"greeting\": u\"\u3053\u3093\u306b\u3061\u306f\",\n        u\"email\": u\"raphael@hackebrot.de\",\n        u\"docs\": True,\n        u\"gui\": False,\n        u\"lektor\": \"0.0.0.0:5000\",\n        u\"relative-root\": \"/\",\n        123: 456.789,\n        u\"some:int\": 1000000,\n        u\"foo\": u\"hallo #welt\",\n        u\"longtext\": (\n            u\"This is a multiline string. It can contain all \"\n            u\"manners of characters.\\nSingle line breaks are \"\n            u\"ignored, but blank linkes cause line breaks.\\n\"\n        ),\n        u\"trueish\": u\"Falseeeeeee\",\n        u\"blog\": u\"raphael.codes\",\n        u\"doc_tools\": [u\"mkdocs\", u\"sphinx\", None],\n    },\n    u\"zZz\": True,\n    u\"NullValue\": None,\n    u\"Hello World\": {\n        None: u\"This is madness\",\n        u\"gh\": u\"https://github.com/{0}.git\",\n    },\n    u\"Yay #python\": u\"Cool!\",\n}\n```\n\n## Logging\n\npoyo follows the recommendations for [logging in a library][logging], which\nmeans it does not configure logging itself. Its root logger is named ``poyo``\nand the names of all its children loggers track the package/module hierarchy.\npoyo logs to a ``NullHandler`` and solely on ``DEBUG`` level.\n\nIf your application configures logging and allows debug messages to be shown,\nyou will see logging when using poyo. The log messages indicate which parser\nmethod is used for a given string as the parser deseralizes the config. You\ncan remove all logging from poyo in your application by setting the log level\nof the ``poyo`` logger to a value higher than ``DEBUG``.\n\n[logging]: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library\n\n### Disable Logging\n\n```python\nimport logging\n\nlogging.getLogger(\"poyo\").setLevel(logging.WARNING)\n```\n\n### Example Debug Logging Config\n\n```python\nimport logging\nfrom poyo import parse_string\n\nlogging.basicConfig(level=logging.DEBUG)\n\nCONFIG = \"\"\"\n---\ndefault_context: # foobar\n    greeting: \u3053\u3093\u306b\u3061\u306f\n    gui: FALSE\n    doc_tools:\n        # docs or didn't happen\n        -    mkdocs\n        - 'sphinx'\n    123: 456.789\n\"\"\"\n\nparse_string(CONFIG)\n```\n\n### Example Debug Logging Messages\n\n```text\nDEBUG:poyo.parser:parse_blankline <- \\n\nDEBUG:poyo.parser:parse_blankline -> IGNORED\nDEBUG:poyo.parser:parse_dashes <- ---\\n\nDEBUG:poyo.parser:parse_dashes -> IGNORED\nDEBUG:poyo.parser:parse_section <- default_context: # foobar\\n\nDEBUG:poyo.parser:parse_str <- default_context\nDEBUG:poyo.parser:parse_str -> default_context\nDEBUG:poyo.parser:parse_section -> <Section name: default_context>\nDEBUG:poyo.parser:parse_simple <-     greeting: \\u3053\\u3093\\u306b\\u3061\\u306f\\n\nDEBUG:poyo.parser:parse_str <- greeting\nDEBUG:poyo.parser:parse_str -> greeting\nDEBUG:poyo.parser:parse_str <- \\u3053\\u3093\\u306b\\u3061\\u306f\nDEBUG:poyo.parser:parse_str -> \\u3053\\u3093\\u306b\\u3061\\u306f\nDEBUG:poyo.parser:parse_simple -> <Simple name: greeting, value: \\u3053\\u3093\\u306b\\u3061\\u306f>\nDEBUG:poyo.parser:parse_simple <-     gui: FALSE\\n\nDEBUG:poyo.parser:parse_str <- gui\nDEBUG:poyo.parser:parse_str -> gui\nDEBUG:poyo.parser:parse_false <- FALSE\nDEBUG:poyo.parser:parse_false -> False\nDEBUG:poyo.parser:parse_simple -> <Simple name: gui, value: False>\nDEBUG:poyo.parser:parse_list <-     doc_tools:\\n        # docs or didn't happen\\n        -    mkdocs\\n        - 'sphinx'\\n\nDEBUG:poyo.parser:parse_str <- mkdocs\nDEBUG:poyo.parser:parse_str -> mkdocs\nDEBUG:poyo.parser:parse_str <- 'sphinx'\nDEBUG:poyo.parser:parse_str -> sphinx\nDEBUG:poyo.parser:parse_str <- doc_tools\nDEBUG:poyo.parser:parse_str -> doc_tools\nDEBUG:poyo.parser:parse_list -> <Simple name: doc_tools, value: ['mkdocs', 'sphinx']>\nDEBUG:poyo.parser:parse_simple <-     123: 456.789\\n\nDEBUG:poyo.parser:parse_int <- 123\nDEBUG:poyo.parser:parse_int -> 123\nDEBUG:poyo.parser:parse_float <- 456.789\nDEBUG:poyo.parser:parse_float -> 456.789\nDEBUG:poyo.parser:parse_simple -> <Simple name: 123, value: 456.789>\nDEBUG:poyo.parser:parse_simple <-     docs: true\\n\nDEBUG:poyo.parser:parse_str <- docs\nDEBUG:poyo.parser:parse_str -> docs\nDEBUG:poyo.parser:parse_true <- true\nDEBUG:poyo.parser:parse_true -> True\nDEBUG:poyo.parser:parse_simple -> <Simple name: docs, value: True>\n```\n\n## About this project\n\nWe created this project to work around installation issues with a\n[cookiecutter][cookiecutter] version that depended on existing YAML parsers\nfor Python. For more information please check out this [GitHub issue][issue].\n\n[issue]: https://github.com/cookiecutter/cookiecutter/pull/621\n\n## Community\n\nWould you like to contribute to **poyo**? You're awesome! \ud83d\ude03\n\nPlease check out the [good first issue][good first issue] label for tasks,\nthat are good candidates for your first contribution to poyo. Your\ncontributions are greatly appreciated! Every little bit helps and credit will\nalways be given.\n\nEveryone interacting in the poyo project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the [PyPI Code of\nConduct][code of conduct].\n\nJoin the poyo [community][community]! \ud83c\udf0d\ud83c\udf0f\ud83c\udf0e\n\n[code of conduct]: https://www.pypa.io/en/latest/code-of-conduct/\n[community]: https://github.com/hackebrot/poyo/blob/master/COMMUNITY.md\n[good first issue]: https://github.com/hackebrot/poyo/labels/good%20first%20issue\n\n## License\n\nDistributed under the terms of the [MIT][MIT] license, poyo is free and open source\nsoftware.\n\n[MIT]: https://github.com/hackebrot/poyo/blob/master/LICENSE\n\n[cookiecutter]: https://github.com/cookiecutter/cookiecutter\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight YAML Parser for Python. \ud83d\udc13",
    "version": "0.5.0",
    "split_keywords": [
        "yaml",
        "parser",
        "cookiecutter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "20c1a169db35ca9ca81265038b801385",
                "sha256": "3e2ca8e33fdc3c411cd101ca395668395dd5dc7ac775b8e809e3def9f9fe041a"
            },
            "downloads": -1,
            "filename": "poyo-0.5.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20c1a169db35ca9ca81265038b801385",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
            "size": 10183,
            "upload_time": "2019-07-26T12:51:02",
            "upload_time_iso_8601": "2019-07-26T12:51:02.939138Z",
            "url": "https://files.pythonhosted.org/packages/42/50/0b0820601bde2eda403f47b9a4a1f270098ed0dd4c00c443d883164bdccc/poyo-0.5.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "87105d14ce1ea656f816bd0af001cfe1",
                "sha256": "e26956aa780c45f011ca9886f044590e2d8fd8b61db7b1c1cf4e0869f48ed4dd"
            },
            "downloads": -1,
            "filename": "poyo-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "87105d14ce1ea656f816bd0af001cfe1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
            "size": 15276,
            "upload_time": "2019-07-26T12:51:04",
            "upload_time_iso_8601": "2019-07-26T12:51:04.855586Z",
            "url": "https://files.pythonhosted.org/packages/7d/56/01b496f36bbd496aed9351dd1b06cf57fd2f5028480a87adbcf7a4ff1f65/poyo-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-07-26 12:51:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hackebrot",
    "github_project": "poyo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "poyo"
}
        
Elapsed time: 0.02274s