Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bigjason/datatree

Pythonic, low noise structured document authoring
https://github.com/bigjason/datatree

Last synced: 3 months ago
JSON representation

Pythonic, low noise structured document authoring

Awesome Lists containing this project

README

        

-------
Summary
-------
DataTree is a library for creating structured documents in python. Inspired by
`ruby builder`_ but with the goal of reducing the amount of line noise while
remaining "pythonic". 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_ repository.

To install with pip::

$ pip install datatree

To install with easy_install::

$ easy_install datatree

---------------------
About the 0.2.0 Alpha
---------------------
Version 0.2.0 is about 70% complete. The remaining tasks are:

#. Implement xml namespaces.
#. Finish updating documentation to the new API.
#. Make the ``Node`` callable the same as the ``node`` method.

Installing the Alpha
--------------------
You can install the alpha with pip directly from github using the command::

$ pip install -e git://github.com/bigjason/[email protected]#egg=datatree

-------
Example
-------
A small example::

from datatree import Tree, Node

tree = Tree()
with tree.node("author") as author:
author.node('name', 'Terry Pratchett')
author.node('genre', 'Fantasy/Comedy')
author.comment("Only 2 books listed")
with author.node('novels', count=2) as novels:
novels.node('novel', 'Small Gods', year=1992)
novels.node('novel', 'The Fifth Elephant', year=1999)
novels.node("novel", "Guards! Guards!", year=1989)

print tree(pretty=True)

Which produces the XML::


Terry Pratchett
Fantasy/Comedy


Small Gods
The Fifth Elephant
Guards! Guards!

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 (preferably) on twitter
`@bigjasonwebb `_.

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

.. _ruby builder: http://builder.rubyforge.org/
.. _github: https://github.com/bigjason/datatree