Skip to main content

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 datatree.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, Node

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 Apache License, Version 2.0.

Souce Code

The source code can be found on github.

Feedback

I welcome any and all constructive feedback. Feel free to contact me (Jason Webb) at www.bigjason.com or on twitter @bigjasonwebb.

Contributing

Contributions are welcome. Just fork on github and I will try to be as responsive as possible.

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

datatree-0.1.8.1.tar.gz (12.5 kB view details)

Uploaded Source

File details

Details for the file datatree-0.1.8.1.tar.gz.

File metadata

  • Download URL: datatree-0.1.8.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for datatree-0.1.8.1.tar.gz
Algorithm Hash digest
SHA256 8827beeff680842c70dad7f52e57b3d7044f2a4749a7e1e1516517fb5f443a84
MD5 71171dbf4b9ef7d07bc01b4a962af3a8
BLAKE2b-256 f458dd010d582126b58e67e21f4d6dbd08bc6cdb53879b045c2cc627892ff978

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page