Skip to main content

Import, filter and export tabular data with Python easily

Project description

outputty is a simple Python library that helps you importing, filtering and exporting data. It is composed by a main Table class and a lot of plugins that helps importing and exporting data to/from Table.

You can write your own plugin easily (see outputty/plugin_*.py for examples). Some examples of plugins are: CSV, text, HTML and histogram.

Installation

As simple as executing:

pip install outputty

Note: as pip tries to compile everything and outputty depends on MySQL-Python package (which needs compilation), you need to have libmysqlclient’s headers, compilers and related stuff. To install it on Debian/Ubuntu, just execute:

apt-get install build-essential libmysqlclient-dev

Example

Code time!:

>>> 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 have a lot of other features. To learn more (by examples), read outputty tutorial and see examples folder. Enjoy!

New Features

Yes, there are a lot of features to add (it’s just the begining). If you want to contribute, please see our outputty wishlist.

You can also use the outputty Issue Tracking System on GitHub to report bugs.

Contributing

If you want to contribute to this project, please:

  • Install dependencies for development running pip install -r requirements/development.txt.

  • Execute make test to run all tests – please run all tests before pushing.

    • To run just one test file execute: nosetests --with-coverage --cover-package outputty tests/test_your-test-file.py

    • Try to have a test-coverage of 100%.

    • Use Test-driven development.

  • Use nvie’s gitflow - to learn, read A Successful Git branching model.

  • Create/update documentation (README/docstrings/man page)

    • Do NOT edit README.rst and tutorial.rst, edit README-template.rst or tutorial-template.rst instead and run make create-docs to create the new README.rst and tutorial.rst (before committing). The tutorial will be created based on files in examples folder.

New Plugins

If you want to create a new plugin to import/export from/to some new resource, please see files outputty/plugin_*.py as examples. They are so simple, please follow these steps:

  • Create a file named outputty/plugin_name.py, where name is the name of your plugin.

  • Create read and/or write functions in this file. These functions receive the Table object and optional parameters.

    • read: should read data from the resource specified in parameters and put this data in Table (using Table.append or Table.extend).

    • write: should read data from Table (iterating over it, using slicing etc.) and write this data to the resource specified in parameters.

  • Call your plugin executing my_table.write('name', optional_parameters...) or my_table.read('name', optional_parameters...) (where name is your plugin’s name) - when you execute it outputty will call outputty.plugin_name.read/outputty.plugin_name.write.

Encoding and Decoding

Your plugin’s read function must put all data inside in unicode and your plugin’s write function will receive a Table object with all data in unicode (it should not change this). But if you need to decode/encode before/after doing some actions in your plugin, you can use Table.decode() and Table.encode().

Contributors

This software is written and maintained by Álvaro Justen but received a lot of contributions. My sincerely thanks to:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

outputty-0.3.2.tar.gz (29.2 kB view details)

Uploaded Source

File details

Details for the file outputty-0.3.2.tar.gz.

File metadata

  • Download URL: outputty-0.3.2.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for outputty-0.3.2.tar.gz
Algorithm Hash digest
SHA256 dadb14e78d247bc83231be39ffe5b2f37226d848c43072856bf668f24b1da3e3
MD5 99827c885f2fd4deab1413c9a94710eb
BLAKE2b-256 2fcea096863529d5d9230d54cbacbe629a57c490d6f9dd443757cfb5801f9e3d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page