DSL for creating structured documents in python.
Project description
Summary
DataTree is a DSL for creating structured documents in python. Inspired by ruby builder but with the goal of reducing the amount of line noise associated with creating XML documents in python. As an added bonus the tree can be output to to any structured format (with XML, JSON and YAML supported in the library).
Note: More documentation is coming soon but for now a very basic rough draft can be found at readthedocs.org.
Installation
You can install via PyPi or direct from the github repo.
To install with pip:
$ pip install datatree
To install with easy_install:
$ easy_install datatree
Example
A small example:
from datatree import Tree tree = Tree() with tree.author() as author: author.name('Terry Pratchett') author.genre('Fantasy/Comedy') author // "Only 2 books listed" with author.novels(count=2) as novels: novels.novel('Small Gods', year=1992) novels.novel('The Fifth Elephant', year=1999) novels << Node("novel", "Guards! Guards!", year=1989) print tree(pretty=True)
Which produces the XML:
<author> <name>Terry Pratchett</name> <genre>Fantasy/Comedy</genre> <!-- Only 2 books listed --> <novels count="2"> <novel year="1992">Small Gods</novel> <novel year="1999">The Fifth Elephant</novel> <novel year="1989">Guards! Guards!</novel> </novels> </author>
Or the JSON:
{ "author": { "genre": "Fantasy/Comedy", "name": "Terry Pratchett", "novels": [ "Small Gods", "The Fifth Elephant", "Guards! Guards!" ] } }
Or the YAML:
author: genre: Fantasy/Comedy name: Terry Pratchett novels: [Small Gods, The Fifth Elephant, Guards! Guards!]
License
This work is licensed under the Creative Commons Attribution 3.0 Unported License. You can view a copy of this license here.
Souce Code
The source code can be found on github.
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
File details
Details for the file datatree-0.1.6.tar.gz
.
File metadata
- Download URL: datatree-0.1.6.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71cf878ec75022ff2f346a0ea937b9eee67d2455f2b0526c9d5d37213210bbfd |
|
MD5 | 586aac8dd8a485ff7a22e80e20d2cd3b |
|
BLAKE2b-256 | 9af1e6b3cb63c6b80683861ef6b908b346dfe4a72be93ec7340d6adfd13cdc73 |