All Projects โ†’ hackebrot โ†’ Poyo

hackebrot / Poyo

Licence: mit
A lightweight YAML Parser for Python. ๐Ÿ“

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Poyo

Succ
Sexy and Utilitarian Code Configuration
Stars: โœญ 100 (-18.7%)
Mutual labels:  config
Wagtail Pipit
Pipit is a Wagtail CMS boilerplate which aims to provide an easy and modern developer workflow with a React-rendered frontend.
Stars: โœญ 109 (-11.38%)
Mutual labels:  cookiecutter
Macos
๐Ÿ’ป When I do a clean macOS installation.
Stars: โœญ 118 (-4.07%)
Mutual labels:  config
Laravel Settings
Persistent key-value storage for Laravel, json value supported. l10n supported.
Stars: โœญ 101 (-17.89%)
Mutual labels:  config
Clear Config
Scala FP configuration library with a focus on runtime clarity
Stars: โœญ 108 (-12.2%)
Mutual labels:  config
Dynaconf
Configuration Management for Python โš™
Stars: โœญ 2,082 (+1592.68%)
Mutual labels:  config
Config Chain
Handle configuration once and for all
Stars: โœญ 98 (-20.33%)
Mutual labels:  config
Data Store
Easily get, set and persist config data. Fast. Supports dot-notation in keys. No dependencies.
Stars: โœญ 120 (-2.44%)
Mutual labels:  config
Electrode Confippet
node.js environment aware application configuration
Stars: โœญ 109 (-11.38%)
Mutual labels:  config
Dnjs
DOM Notation JS
Stars: โœญ 118 (-4.07%)
Mutual labels:  config
Cookiecutter Lux Python
Cookiecutter template for an idiomatic Python project driven by Makefile
Stars: โœญ 102 (-17.07%)
Mutual labels:  cookiecutter
Dotfiles
My personal collection of configuration files.
Stars: โœญ 105 (-14.63%)
Mutual labels:  config
Appconfiguration
Questions, feedback and samples for Azure App Configuration service
Stars: โœญ 116 (-5.69%)
Mutual labels:  config
.personal Emacs.d
๐Ÿ˜ˆ My opinionated Emacs configuration
Stars: โœญ 101 (-17.89%)
Mutual labels:  config
Go Config
Robust application configuration made simple
Stars: โœญ 117 (-4.88%)
Mutual labels:  config
Dots
A Repository For Config Files / Dotfiles / Themes / Color Schemes / Etc...
Stars: โœญ 100 (-18.7%)
Mutual labels:  config
Boilerplate
๐Ÿช ML application template to create API services around your ML code.
Stars: โœญ 112 (-8.94%)
Mutual labels:  cookiecutter
Awesome Ban
Awesome WM 4.x theme configs
Stars: โœญ 122 (-0.81%)
Mutual labels:  config
Cookiecutter Reproducible Science
boilerplate for reproducible and transparent science
Stars: โœญ 120 (-2.44%)
Mutual labels:  cookiecutter
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: โœญ 2,105 (+1611.38%)
Mutual labels:  config

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. 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: "[email protected]"
    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"[email protected]",
        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, 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

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

Example Debug Logging Config

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

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 version that depended on existing YAML parsers for Python. For more information please check out this GitHub issue.

Community

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

Please check out the 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.

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

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].