cube package contains tools for setting configuration
options and providing the Jinja template context for
the data model in YAML.
cubepackage is available out of the box, it doesn’t need to be installed explicitly- Submit issues to
cubeon GitHub
Reference
config object
This object is used to set configuration options in the cube.py file.
You can set properties of this object, named after supported configuration
options, to values or functions that would be used
as these configuration options.
name argument. In that case, the decorated function will be set as the
configuration option under that name.
TemplateContext class
Instances of this class are used for registering variables, functions, and
filters so that they are accessible from Jinja templates when defining the
data model in YAML.
add_variable
The add_variable method registers a variable so that it’s available in
a Jinja template. Should be called with two arguments, a name and a value
of the variable.
add_function and function
The add_function method registers a function so that it’s callable from
a Jinja template as a Python function. Should be called with two arguments,
a name and a function that will be registered under that name:
template.function decorator with a single name
argument; the decorated function will be registered under that name:
add_filter and filter
The add_filter method registers a function so that it’s callable from
a Jinja template as a Jinja filter. Should be called
with two arguments, a name and a function that will be registered as a filter
under that name:
template.filter decorator with a single name
argument; the decorated function will be registered as a filter under that
name:
memo decorator
The memo decorator calls a function once per set of arguments during a data
model compilation, then returns the stored result, or raises the stored
exception, on every later call from any template. It works with sync and async
functions. Arguments match when they are equal and of the same type: hashable
values (e.g. numbers, strings, dates or frozen dataclasses), lists, tuples,
dicts and sets. Other objects, e.g. a regular dataclass or self of a method,
match only themselves. Apply it below template.function. Calls made while a
template function runs, including calls between your own Python functions and to
memoized functions imported from other modules, are cached per compilation.
Other calls, e.g., while globals.py loads or to methods of objects a template
function returned, aren’t cached: