tabs package

Submodules

tabs.tables module

Table base classes for defning new tables

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

Bases: object

Abstract Base class for minimum table import

classmethod dep()

dep is an alias of dependencies

classmethod dependencies()[source]

Returns a list of all dependent tables, in the order they are defined.

Add new dependencies for source and every post proecssor like this:

source.dependencies = [PersonalData]
some_post_processor.dependencies = [SomeOtherTable, AnotherTable]

some_post_processor.dependencies needs to be placed after some_post_processor is defined.

classmethod describe(full=False)[source]
Prints a description of the table based on the provided
documentation and post processors.
Parameters:full (bool) – Include post processors in the printed description.
classmethod describe_processors()[source]

List all postprocessors and their description

fetch(rebuild=False, cache=True)[source]

Method for fetching data

get_cached_filename(filename, extention, settings_list=None)[source]

Creates a filename with md5 cache string based on settings list

Parameters:
  • filename (str) – the filename without extention
  • extention (str) – the file extention without dot. (i.e. ‘pkl’)
  • settings_list (dict|list) – the settings list as list (optional) NB! The dictionaries have to be sorted or hash id will change arbitrarely.
get_hash()[source]

Retruns a hash based on the the current table code and kwargs. Also changes based on dependent tables.

get_settings_list()[source]

The settings list used for building the cache id.

output()[source]

Path to the processed table (output path)

post_processors()[source]

A list of functions to be applied for post processing

source()[source]

Path to the original raw data

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

Bases: tabs.tables.BaseTableABC

MetaClass for defining tables.

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

source(self)[source]

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

output(self)[source]

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

post_processors(self)[source]

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(),
        ]
fetch(rebuild=False, cache=True)[source]

Fetches the table and applies all post processors. :param rebuild: Rebuild the table and ignore cache. Default: False :type rebuild: bool :param cache: Cache the finished table for faster future loading.

Default: True
output()[source]

Path to the processed table (output path)

post_processors()[source]

A list of functions to be applied for post processing

read_cache()[source]

Defines how to read table from cache. Should be overwritten if to cache is overwritten

source()[source]

Path to the original raw data

to_cache(table)[source]

Defines the default cache method. Can be overwritten if needed

tabs.tables.describe(cls, full=False)[source]

Prints a description of the table based on the provided documentation and post processors

tabs.tables.post_process(table, post_processors)[source]

Applies the list of post processing methods if any

tabs.tabs module

Tables module

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

Bases: object

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()
describe_all(full=False)[source]

Prints description information about all tables registered :param full: Also prints description of post processors. :type full: bool

find_tabs(custom_table_classes=None)[source]

Finds all classes that are subcalss of Table and loads them into a dictionary named tables.

get(table_name)[source]

Load table class by name, class not yet initialized

load(table_name, **kwargs)[source]

Get table object by name, initialized and ready. Same as using __call__

table_list()[source]

Display the table names

tabs.tabs.get_all_classes(module_name)[source]

Load all non-abstract classes from package

tabs.tabs.get_all_modules(package_path)[source]

Load all modules in a package

Module contents

Tabs