Gura parser
This repository contains the implementation of a Gura format parser in Python.
Installation
pip install gura-parser
Usage
import gura
gura_string = """
# This is a Gura document.
title: "Gura Example"
an_object:
username: "Stephen"
pass: "Hawking"
# Line breaks are OK when inside arrays
hosts: [
"alpha",
"omega"
]
"""
# Loads: transforms a Gura string into a dictionary
parsed_gura = gura.loads(gura_string)
print(parsed_gura) # {'title': 'Gura Example', 'an_object': {'username': 'Stephen', 'pass': 'Hawking'}, 'hosts': ['alpha', 'omega']}
# Access a specific field
print(f"Title -> {parsed_gura['title']}")
# Iterate over structure
for host in parsed_gura['hosts']:
print(f'Host -> {host}')
# Dumps: transforms a dictionary into a Gura string
print(gura.dumps(parsed_gura))
Contributing
All kind of contribution is welcome! If you want to contribute just:
- Fork this repository.
- Create a new branch and introduce there your new changes.
- Make a Pull Request!
Tests
To run all the tests: python -m unittest
. More info in official Unittest docs
Licence
This repository is distributed under the terms of the MIT license.