Basic concepts

Tabs consists of two main classes.
  • Tabs
  • Table

Table

Table is an abstract class used to define new tables. This ensures that all tables has a minimum of shared functionality, like fetching a table or describing it.

class tabs.Table(*args, **kwargs)[source]

MetaClass for defining tables.

Attention! The following methods are required when defining a class the inherits from Table

source(self)

Should return the table. For example pd.read_csv() (required, method)

output(self)

Should return the output path for where the finished table should be stored. For example a cache directory. (required, method)

post_processors(self)

a list of post processor functions of methods. (required, method)

Example

Defining a table:

class UserDataTable(Table):
    def source(self):
        return pd.read_csv('/path/to/file')

    def output(self):
        return "/path/to/output"

    def post_processors(self):
        return [
            my_custom_function(),
            my_second_custom_function(),
        ]

Tabs

Tabs is the class used to load all tables defined in a package. This is the class used for loading tables and gaining an overview of all tables defined in a package.

class tabs.Tabs(package_path=None, custom_table_classes=None)[source]

Class for loading a list of all defined tables, similar to tabs in a browser.

Parameters:
  • package_path (str) – Path to package containing defined tables
  • custom_table_classes (list(class)) – A list of custom Table metaclasses that should also be recognised and added to the tabs list.

Example

Using tabs for listing tables:

from tabs import Tabs
package_path = os.path.dirname(os.path.realpath(__file__))
tabs = Tabs(package_path)
tabs.table_list()

> Avaiable tables:
> Persondata
> OtherData

Fetching a defined table:

person_data = tabs('Persondata').fetch()