Package csb :: Package io :: Module tsv
[frames] | no frames]

Module tsv

source code

Read, query and update textual tables via flexible SQL interface.

Tables can be created and populated with data from scratch, built from TSV files, 2D lists or other tables. Once the data is loaded in memory, each storage operation on the table object is delegated via bridge to an SQL storage backend (by default this is SQLite). However the table uses the backend only as a temp storage to ensure maximum portability of the data. Tables can be stored persistently as text (TSV) files and then loaded back in memory when needed.

These Tables can be queried and updated in a vast number of ways; each query returns a new Table:

  1. Using slice expressions. The general form of a slice expression is [rows, columns], where rows can be:

    and columns can be:

  2. Using query expressions, for example:
    >>> table.where('ID').between(1, 5).select('TmScore', 'RMSD')
    Table ('TmScore', 'RMSD')
    >>> table.where('ID').between(1, 5).update('RMSD', 0.2)
    Table (the same table)
  3. With SQL queries:
    >>> t.query(r'''SELECT  ColumnB * ColumnA AS ComputedValue
                    FROM    {0.name}
                    WHERE   ColumnC IN ({1}, {1})'''.format(t, Predicate.PH),
                [12, 55])
    iterable

The data contained in a Table can be extracted in several ways:

See Table for full API details.

Classes
  Between
  ColumnInfo
Holder object for column metadata.
  DataRow
Represents a table data row.
  Equals
  Expression
Metadata container: represents a table select or update expression.
  Greater
  GreaterOrEquals
  In
  InvalidColumnError
  Lower
  LowerOrEquals
  NotEquals
  NotIn
  Operator
  Predicate
  RepositoryImp
Abstract SQL backend interface.
  SQLiteRepository
SQLite-based concrete repository implementor.
  Step
  Table
Build and query a TSV Table.
  UnsupportedTypeError
  Where
Variables
  __package__ = 'csb.io'