Skip to main content

Simple interface for tabulated data and .csv files

Project description

https://badge.fury.io/py/tabler.svg https://pypip.in/py_versions/tabler/badge.svg https://travis-ci.org/axevalley/tabler.svg?branch=master

Simple interaction with tabulated data

What is tabler?

The tabler package provides the Table class which makes the creation and maniplulation of tabulated data intuitive.

It can:
  • Open various spreadsheet files from a relative path, absolute path or url.

  • Update text in cells.

  • Write files in various formats.

Compatible formats:
  • .csv

  • Open Spreadsheet Format .ods

  • Microsoft Excel .xlsx

  • HTML (Write only)

  • Other filetypes can be added by subclassing the BaseTableType class.

Quick Start

Creating a Table (Basic)

Import the Tabler class from the tabler package and instanciate it with a header and data:

from tabler import Table

table = Tabler(
    header=['SKU', 'Item Title', 'Price'],
    data=[[009, 'Item 1', 5.00], [010, 'Item 2', 9.99]])

Or pass the path to a file to open:

from tabler import Table

Table('path/to/some/file.csv')
This will recognise filetypes with the following extensions:
  • .csv (UTF-8 encoded and comma delimited).

  • .txt (UTF-8 encoded and comma delimited).

  • .xlsx

  • .ods

To explicitly open a file of a specifict type a Table Type object must be provided.:

from tabler import Table
from tabler.tabletypes import CSV

Table('path/to/some/file.csv', table_type=CSV(delimiter='\t'))

These are subclasses of BaseTableType and allow the method of reading the file to be customised.

Reading a Table (Basic)

At its base, Tabler is a two dimensional list. Therefore the simplest way to access a cell is by providing two indexes:

first_cell = table[0][0]

Rows can be indexed by row number (zero based) Tabler will always treat the first line of any supplied data as column headers. This means that a column can be specified by index number or title:

first_item_title = table[0]["Item Title"]

Editing a Table (Basic)

A cell can be edited using the equals = operator:

table[2]["Item Title"] = 'USB Hub'

Cell content can be string, int or float.

Loading Data into a Table (Basic)

Data can be loaded into an empty Tabler object by passing a list of rows in the form of lists of cell data using the Tabler().load_from_array(data, header) method. A list of column headers must be passed as the second argument:

header = ["SKU", "Item Title", "Price"]

data = [
    ["001", "USB Hub", 7.00],
    ["002", "Raspberry Pi 3", 29.99],
    ["003", Arduino Uno", 20.00]
]

table = Tabler()
table.load_from_array(data, header)

Writing a Table to a File (Basic)

Writing a file is similar to reading a file. Table Types are used in the same way to manage writing files:

table.write('path/to/save.csv', table_type=CSV(delimiter='\t')

The table type will be set automatically for reconised file extensions if not explicitly set.

Contact

All comments and queries can be sent to Luke Shiner at luke@lukeshiner.com

License

Distributed with MIT License.

Credits

Created by Luke Shiner (luke@lukeshiner.com)

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

tabler-2.2.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

tabler-2.2-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file tabler-2.2.tar.gz.

File metadata

  • Download URL: tabler-2.2.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tabler-2.2.tar.gz
Algorithm Hash digest
SHA256 ed8473d4cf78b37cfbfd3be658fac412789e8b4f0138cf0ebbe558fedb6a353f
MD5 07673af9e08756ff8ce0eba2b112652a
BLAKE2b-256 c89cfb06bb12079c7ad3b32b97bed6dcc48d4d54311933c014d937627bd387c1

See more details on using hashes here.

File details

Details for the file tabler-2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tabler-2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc70afd6ea3ba93b31ffd7c9a8e4bebf5940ac4cbe14ba5644f03c3c1e157e5
MD5 1089ff0dfc863c3ba9acd97860a800e7
BLAKE2b-256 69b87fc329aab81f881b4b60964ae30c33280564baf00258900765fc7ce89602

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