A Python library for the KDL Document Language.
Project description
python-cuddle
A Python library for the KDL Document Language.
Install
pip install cuddle
Or if you're using poetry:
poetry add cuddle
Cuddle supports Python 3.9 and above.
Usage
from cuddle import Document, Node, NodeList, dumps, loads
loaded_doc = loads('''// Nodes can be separated into multiple lines
title \
"Some title"
// Nested nodes are fully supported
contents {
section "First section" {
paragraph "This is the first paragraph"
paragraph "This is the second paragraph"
}
}
// 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
''')
print(dumps(loaded_doc))
print()
# Creating documents from scratch is a bit verbose
nodes = []
child_node = Node("complex name here!", None)
nodes.append(
Node("simple-name", None, arguments=[123], children=[child_node])
)
nodes.append(
Node("second-node", None, properties={"key": "value"})
)
node_list = NodeList(nodes)
doc = Document(node_list)
print(dumps(doc))
The output:
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!"
}
second-node key="value"
License
The code is available under the MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cuddle-1.0.6.tar.gz
(37.0 kB
view details)
Built Distribution
cuddle-1.0.6-py3-none-any.whl
(15.7 kB
view details)
File details
Details for the file cuddle-1.0.6.tar.gz
.
File metadata
- Download URL: cuddle-1.0.6.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ad9ac0077cdccc8b6b85794635c895a91fe312a3d9f8d1cb4c7591921fb06c5 |
|
MD5 | 7159ab43a94950d361d3576fbe297cc6 |
|
BLAKE2b-256 | 520d431efa5679a6b7fa01c49463b8371ade2ed20b91af7b79eeda8f039500b8 |
File details
Details for the file cuddle-1.0.6-py3-none-any.whl
.
File metadata
- Download URL: cuddle-1.0.6-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbf0163b069bd0a9cfe0493d07388cfdbf2641bfd285fd2fb546094e58018fc3 |
|
MD5 | a20b3b21c8fc4ca1f6e32421831514ba |
|
BLAKE2b-256 | b04b7b5ead7c30116a7b4124baa3a390c7d76ac9f84fcc32f1f11eab40c03fd9 |