https://github.com/crdoconnor/usy
Ultra-simple YAML - Roundtrippable YAML parser that only parses comments and a flat list of key/value pairs.
https://github.com/crdoconnor/usy
parser python simple yaml
Last synced: about 1 month ago
JSON representation
Ultra-simple YAML - Roundtrippable YAML parser that only parses comments and a flat list of key/value pairs.
- Host: GitHub
- URL: https://github.com/crdoconnor/usy
- Owner: crdoconnor
- License: bsd-2-clause
- Created: 2017-03-07T19:10:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-14T13:56:08.000Z (about 8 years ago)
- Last Synced: 2025-03-17T19:48:02.209Z (over 1 year ago)
- Topics: parser, python, simple, yaml
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
Ultra Simple YAML
=================
Ultra Simple YAML is a tiny module designed to parse a *very*
restricted subset of YAML. It is a sister project of
`StrictYAML `_
which parses a larger subset of YAML (still restricted, albeit
for different reasons).
It is designed to be includeable in larger projects where
including an entire additional module is not desirable or possible
but you still don't want to use INI.
It is licensed with a BSD-2 Clause license - the least restrictive
possible.
Install
-------
All the code is in one file: usy.py. Simply copy that file into
your code base.
Usage
-----
Given the following file example.yaml:
.. code-block:: yaml
# Simple YAML file
property1: value1
property2: 2
Copy the file usy.py into your project and use:
.. code-block:: python
>>> with open('example.yaml', 'r') as handle:
>>> contents = handle.read()
>>> parsed = usy.load(contents)
>>> parsed
USY({"property1": "value1", "property2": "2"})
>>> parsed["property1"]
value1
>>> parsed["property2"] == "2"
True
>>> parsed["property3"] = "3"
>>> parsed.as_yaml()
# Simple YAML file
property1: value1
property2: 2
property3: 3
What can and cannot be parsed?
------------------------------
* Only key/value pairs and comments will be parsed.
* No nested key/value pairs will be parsed or saved.
* No lists will be parsed.
* All values will be parsed as strings.