Python中创建结构化文档的DSL。
项目描述
摘要
DataTree是一个用于在Python中创建结构化文档的DSL。受ruby builder的启发,但旨在减少Python中创建XML文档时相关的行噪声。作为额外的奖励,树可以输出到任何结构化格式(库支持XML、JSON和YAML)。
注意: 更多文档即将推出,但到目前为止,可以在datatree.readthedocs.org找到一个非常基本的草稿。
安装
使用pip安装
$ pip install datatree
使用easy_install安装
$ easy_install datatree
示例
一个小示例
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!" ] } }
或YAML
author: genre: Fantasy/Comedy name: Terry Pratchett novels: [Small Gods, The Fifth Elephant, Guards! Guards!]
许可
此作品根据Apache许可证版本2.0授权。
源代码
源代码可在github上找到。
反馈
我欢迎任何和所有的建设性反馈。请随时通过www.bigjason.com或twitter @bigjasonwebb联系我(Jason Webb)。
贡献
欢迎贡献。只需在github上进行分叉,我会尽可能做出响应。
项目详情
关闭
datatree-0.1.8.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8827beeff680842c70dad7f52e57b3d7044f2a4749a7e1e1516517fb5f443a84 |
|
MD5 | 71171dbf4b9ef7d07bc01b4a962af3a8 |
|
BLAKE2b-256 | f458dd010d582126b58e67e21f4d6dbd08bc6cdb53879b045c2cc627892ff978 |