daeken / kdl-py

Python implementation of the KDL Document Language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kdl-py

A Python library for the KDL Document Language.

Install

pip install kdl-py

kdl-py is fully Python 2.7 and Python 3 friendly.

Usage

from kdl import parse, Document, Node
print(parse('''// Nodes can be separated into multiple lines
title \
  "Some title"


// Files must be utf8 encoded!
smile "๐Ÿ˜"

// Instead of anonymous nodes, nodes and properties can be wrapped
// in "" for arbitrary node names.
"!@#$@$%Q#$%~@!40" "1.2.3" "!!!!!"=true

// The following is a legal bare identifier:
foo123~!@#$%^&*.:'|/?+ "weeee"

// And you can also use unicode!
ใƒŽใƒผใƒ‰ ใŠๅๅ‰="โ˜œ(๏พŸใƒฎ๏พŸโ˜œ)"

// kdl specifically allows properties and values to be
// interspersed with each other, much like CLI commands.
foo bar=true "baz" quux=false 1 2 3
'''))

# Creating documents from scratch is currently very gross
print()
doc = Document()
doc.append(Node(name='simple-name', properties=None, arguments=[123], children=[Node(name='complex name here!', properties=None, arguments=None, children=None)]))
print(doc)
title "Some title"
smile "๐Ÿ˜"
!@#$@$%Q#$%~@!40 !!!!!=true "1.2.3"
foo123~!@#$%^&*.:'|/?+ "weeee"
ใƒŽใƒผใƒ‰ ใŠๅๅ‰="โ˜œ(๏พŸใƒฎ๏พŸโ˜œ)"
foo bar=true quux=false "baz" 1 2 3

simple-name 123 {
        "complex name here!"
}

License

The code is available under the MIT license. The example above is made available from https://github.com/kdl-org/kdl under Creative Commons Attribution-ShareAlike 4.0 International.

About

Python implementation of the KDL Document Language

License:MIT License


Languages

Language:Python 100.0%