使用Python轻松导入、过滤和导出表格数据
项目描述
outputty 是一个简单的Python库,帮助您导入、过滤和导出数据。它由主要的 Table 类和许多插件组成,这些插件帮助将数据从 Table 导入和导出。
您可以轻松编写自己的插件(查看 outputty/plugin_*.py 以获取示例)。一些插件的示例包括:CSV、文本、HTML和直方图。
安装
就像执行一样简单
pip install outputty
注意:由于 pip 尝试编译所有内容,并且 outputty 依赖于 MySQL-Python 软件包(该软件包需要编译),因此您需要安装 libmysqlclient 的头文件、编译器和相关内容。要在 Debian/Ubuntu 上安装它,只需执行
apt-get install build-essential libmysqlclient-dev
示例
编码时间!
>>> from outputty import Table >>> my_table = Table(headers=['name', 'age']) # headers are the columns >>> my_table.append(('Álvaro Justen', 24)) # a row as tuple >>> my_table.append({'name': 'Other User', 'age': 99}) # a row as dict >>> print my_table # a text representation of Table +---------------+-----+ | name | age | +---------------+-----+ | Álvaro Justen | 24 | | Other User | 99 | +---------------+-----+ >>> print 'First row:', my_table[0] # Table is indexable First row: [u'\xc1lvaro Justen', 24] >>> print 'Sum of ages:', sum(my_table['age']) # you can get columns too Sum of ages: 123 >>> my_table.write('csv', 'my-table.csv') # CSV plugin will save its contents in a file >>> # let's see what's in the file... >>> print open('my-table.csv').read() "name","age" "Álvaro Justen","24" "Other User","99" >>> # let's use HTML plugin! >>> print my_table.write('html') # without filename ``write`` will return a string <table> <thead> <tr class="header"> <th>name</th> <th>age</th> </tr> </thead> <tbody> <tr class="odd"> <td>Álvaro Justen</td> <td>24</td> </tr> <tr class="even"> <td>Other User</td> <td>99</td> </tr> </tbody> </table>
Table 具有许多其他功能。要了解更多信息(通过示例),请阅读 outputty教程 并查看示例文件夹。祝您享受!
新功能
是的,还有很多功能要添加(这只是个开始)。如果您想贡献力量,请参阅我们的outputty愿望清单。
您还可以使用GitHub上的outputty问题跟踪系统来报告错误。
贡献力量
如果您想为这个项目贡献力量,请
运行
pip install -r requirements/development.txt
安装开发所需的依赖。执行
make test
以运行所有测试 - 在推送之前请运行所有测试。要运行单个测试文件,请执行:
nosetests --with-coverage --cover-package outputty tests/test_your-test-file.py
尽量实现100%的测试覆盖率。
使用测试驱动开发。
使用nvie的gitflow - 要了解,请阅读一个成功的Git分支模型。
创建/更新文档(README/docstrings/man页面)
不要编辑
README.rst
和tutorial.rst
,而是编辑README-template.rst
或tutorial-template.rst
,然后运行make create-docs
来创建新的README.rst
和tutorial.rst
(在提交之前)。教程将基于examples
文件夹中的文件创建。
新插件
如果您想创建一个新插件来从/到某些新资源导入/导出,请参阅文件outputty/plugin_*.py
作为示例。它们非常简单,请按照以下步骤操作
创建一个名为
outputty/plugin_name.py
的文件,其中name
是您插件的名字。在此文件中创建
read
和/或write
函数。这些函数接收Table
对象和可选参数。read
:应从参数中指定的资源读取数据,并将此数据放入Table
(使用Table.append
或Table.extend
)。write
:应从Table
读取数据(迭代它,使用切片等),并将这些数据写入参数中指定的资源。
通过执行
my_table.write('name', optional_parameters...)
或my_table.read('name', optional_parameters...)
(其中name
是您插件的名字)来调用您的插件 - 当您执行它时,outputty
将调用outputty.plugin_name.read
/outputty.plugin_name.write
。
编码和解码
您的插件中的read
函数必须将所有数据放在内部以unicode格式,您的插件中的write
函数将接收到一个包含所有数据为unicode的Table
对象(它不应更改此格式)。但如果您需要在插件中的某些操作前后进行解码/编码,您可以使用Table.decode()
和Table.encode()
。
贡献者
此软件由Álvaro Justen编写和维护,但收到了许多贡献。我衷心感谢
Fundação Getúlio Vargas允许我将时间投入到其中。
Douglas Andrade为我展示了textwrap.dedent并编写了更易读的测试。
Flávio Coelho创建了histogram并提出了很多建议。
Renne Rocha 为创建 order_by 做出了贡献。
Tatiana Al-Chueyr 设计并编码了插件 API 的架构建议和提案(包括我们正在使用的架构)。
Flávio Amieiro 对设计提出了许多建议和解读。
项目详情
outputty-0.3.2.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | dadb14e78d247bc83231be39ffe5b2f37226d848c43072856bf668f24b1da3e3 |
|
MD5 | 99827c885f2fd4deab1413c9a94710eb |
|
BLAKE2b-256 | 2fcea096863529d5d9230d54cbacbe629a57c490d6f9dd443757cfb5801f9e3d |