用于在python中创建结构化文档的dsl。
datatree的Python项目详细描述
摘要
datatree是用python创建结构化文档的dsl。灵感来自 ruby builder但目的是减少相关的线噪声 在python中创建xml文档。作为额外的奖励,可以输出树 到任何结构化格式(库中支持xml、json和yaml)。
注意:很快就会有更多的文档,但是现在一个非常基本的草稿可以是 在datatree.readthedocs.org找到。
示例
一个小例子:
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)
生成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>
或者json:
{ "author": { "genre": "Fantasy/Comedy", "name": "Terry Pratchett", "novels": [ "Small Gods", "The Fifth Elephant", "Guards! Guards!" ] } }
或者山药:
author: genre: Fantasy/Comedy name: Terry Pratchett novels: [Small Gods, The Fifth Elephant, Guards! Guards!]
许可证
这项工作是根据Apache License, Version 2.0授权的。
源代码
源代码可以在github上找到。
反馈
我欢迎任何和所有建设性的反馈。随时联系我(杰森·韦伯) www.bigjason.com或在twitter上 @bigjasonwebb。
贡献
欢迎捐款。只要在github上叉子,我会尽量做出反应 尽可能的。