Skip to content

Latest commit

 

History

History
59 lines (47 loc) · 1.34 KB

README.md

File metadata and controls

59 lines (47 loc) · 1.34 KB

yacp

Yet Another Config Parser. Convert YAML, JSON, and Custom files to python objects and back.

Parsers

  • JsonParser uses inbuilt json module
  • YamlParser uses inbuilt yaml module
  • CustomParser uses a simple parser which requires a syntax to be passed.

Get the package

  1. Install using pip
pip3 install git+https://github.com/AP-Atul/yacp
  1. Clone and install
git clone https://github.com/AP-Atul/yacp
python3 setup.py install

Usage

  1. Buid a class with members (or without)
class Settings:
    def __init__(self):
        self._name = None
        self._age = None

settings = Settings()
  1. Loading a file into the object
## the parser type will be determined using the file name
settings = yacp.load(filename=YOUR_FILE, cls=OBJECT)
  1. Dumping an object
yacp.dump(filename=YOUR_FILE, cls=OBJECT)
  • For custom files use syntax attribute [NOTE: Primitive data types are preserved using regexps]
# syntax should contain two strings (key, val)
object = yacp.load(filename=FILE, cls=OBJECT, syntax="%s:%s")
yacp.dump(filename=FILE, cls=OBJECT, syntax="%s:%s")
  • Use override for class with no members [This will add attributes to the object that are not declared in the class but available in the file]
object = yacp.load(filename, cls, override=True)