API Reference
TTR main class reference
- class ttr.ttr(data=None, data_plugin=None, data_plugin_kwargs=None, renderer='jinja2', validator='yangson', renderer_kwargs=None, templates='./Templates/', models_dir='./Models/', template_name_key='template', model_name_key='model', returner='self', returner_kwargs=None, result_name_key='device', processors=None, processors_kwargs=None, templates_dict=None, models_dict=None, validator_kwargs=None)
Main class to instantiate TTR object.
- Parameters
data – (str) type depends on data plugin in use, but can be an OS path string referring to YAML structured text file or CSV spreadsheet
data_plugin – (str) name of data plugin to use to load data
data_plugin_kwargs – (dict) arguments to pass on to data plugin
renderer – (str) name of renderer plugin to use, default
jinja2
renderer_kwargs – (dict) arguments to pass on to renderer plugin
templates – (str) OS pat to directory or excel spreadsheet file with templates, defaults to
./Templates/
foldertemplate_name_key – (str) name of the key in data items that reference template to use to render that particular datum, default
template
returner – (str) name of returner plugin to use, default
self
returner_kwargs – (dict) arguments to pass on to returner plugin
result_name_key – (str) name of the key in data items value of which should be used as a key in results dictionary, default
device
processors – (list) list of processor plugins names to pass loaded data through, default is empty list - no processors applied
templates_dict – (dict) dictionary of {template_name: template_content}
models_dir – (str) OS path to directory or with data models, defaults to
./Models/
foldermodel_name_key – (str) name of the key in data items that reference model to use to validate that particular datum, default
model
models_dict – (dict) dictionary of {model_name: model_content}
validator – (str) validator plugin to use to validate provided data against models, default is
yangson
validator_kwargs – (dict) arguments to pass on to validator plugin
- load_data(data, data_plugin=None)
Method to load data to render.
- Parameters
data – (str) data to load, either OS path to data file or text
data_plugin – (str) name of data plugin to load data, by default will choose data loader plugin based on file extension e.g.
xlsx, csv, yaml/yml
- load_models(models_dir=None, model_plugin=None, **kwargs)
Function to load models content to models dictionary.
- Parameters
models_dir – (str) OS path to directory with models, defaults to
./Models/
directorymodel_plugin – (str) models loader plugin to use -
yangson
(default)kwargs – any additional
**kwargs
to pass on tomodel_plugin
call
- load_templates(template_name='', template_content='', templates='', templates_plugin='', **kwargs)
Function to load templates content in templates dictionary.
- Parameters
template_name – (str) name of template to load
template_content – (str) template content to save in templates dictionary under
template_name
templates – (str) OS pat to directory or file with templates, default
./Templates/
templates_plugin – (str) templates loader plugin to use -
base, xlsx, dir, file, ttr
kwargs – any additional
**kwargs
to pass on totemplates_plugin
Decision logic:
If
template_content
provided add it to templates dictionary undertemplate_name
keyIf valid
templates_plugin
name given use it to load templateUse
base
templates loader plugin to load template content
- process_data(data)
Function to pass loaded data through a list of processor plugins.
- Parameters
data – (list) list of dictionaries data to process
- Returns
processed data
- run()
Method to render templates with data and produce dictionary results keyed by
result_name_key
.If returner set to
self
, will return results dictionary.
- run_returner(results=None, returner=None, **kwargs)
Function to run returner to return results via plugin of choice.
- Parameters
results – (dict) results to run returner for
returner – (str) returner plugin name e.g. self, file, terminal
kwargs – (dict) additional arguments for returner plugin
- validate_data(data)
Function to validate provided data
- Parameters
data – (list) list of dictionaries data to validate
- Returns
None
Running validation raises or logs error on validation failure depending on value of
on_fail
argument invalidator_kwargs