跳转到主要内容

Python中创建结构化文档的DSL。

项目描述

摘要

DataTree是一个用于在Python中创建结构化文档的DSL。受ruby builder的启发,但旨在减少Python中创建XML文档时相关的行噪声。作为额外的奖励,树可以输出到任何结构化格式(库支持XML、JSON和YAML)。

注意: 更多文档即将推出,但到目前为止,可以在datatree.readthedocs.org找到一个非常基本的草稿。

安装

您可以通过PyPi或直接从github存储库进行安装。

使用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 (12.5 kB 查看哈希值)

上传时间

支持者