API Reference¶
Bento class¶
The fundamental Bento class that ties all of Bento’s functionality together.
-
class
bento.bento.
Bento
(descriptor: Dict, init_only: bool = False)[source]¶ Acts as the gateway to all Bento functionality.
- descriptordict
The descriptor contains all of the user-supplied information defining the desired dashboard. See the user guide for creating a descriptor.
- init_onlybool
Supply True in order to halt the automatic processing of the descriptor. This can be useful for debugging or modifying the standard app-creation process.
-
desc
¶ This stores the normalized version of the input descriptor.
- Type
dict
-
data
¶ Contains the data as a dictionary. TODO
- Type
dict
-
valid
¶ Whether the descriptor meets the schema. If False, will block processing.
- Type
bool
-
context
¶ Specifies the app for consumption by a Jinja template.
- Type
dict
Examples
- Simple:
>>> bento = Bento(my_descriptor) >>> bento.write()
- Advanced:
>>> bento = Bento(my_descriptor, init_only=True) >>> test_page = bento.desc["pages"]["test"] >>> bento.create_page("test", test_page) >>> bento.context["pages"]["test"] = alternate_grid_method(test_page) >>> bento.connect_page(test_page) >>> bento.write(app_output="modified_test_layout.py")
-
connect_page
(page: Dict)[source]¶ Applies the requested connections for the page to the Jinja context
A page is a set of connected banks, and the connections are defined by a supplied directed graph (dict of sets) of bank_ids. For example, {‘axes’: {‘map’, ‘counter’}, ‘colors’: {‘map’}} tells us the axes bank should feed both the map and counter banks, while our colors bank should feed just the map.
-
create_page
(pageid: str, page: Dict)[source]¶ Generates and lays out all banks defined for a page and updates the context
A page is composed of a set of banks, arranged based on a supplied layout object (an array of 2+ dim).
-
is_valid
(descriptor: Dict) → bool[source]¶ Ensures the descriptor meets the Cerberus schema (see schema.py)
Descriptor schema¶
- To get a quick sense of the schema, I recommend looking at the following examples:
A bare-bones dash - Run
python3 -m bento.dashboards.simple
thenpython3 bento_app.py
to viewThe demo dash - Run
bento-demo
to see it in action
The full schema follows, which, for now, is a simple dump of the Cerberus schema:
# Page and bank ids, are strings of word characters only with length 2+
# No trailing, leading, or double underscores
bento_uid_regex = r"^(?!_|.*_$|.*__.*)[a-z0-9_]{2,}$"
# One or more words separated by a space
words_regex = r"^\w+( \w+)*$"
page_schema = {
"banks": {
"type": "dict",
"required": True,
"allow_unknown": True,
"minlength": 1,
"keysrules": {"type": "string", "regex": bento_uid_regex},
"valuesrules": {
"type": "dict",
"allow_unknown": True,
"schema": {
"type": {"type": "string", "required": True, "regex": bento_uid_regex},
"width": {"type": "integer"},
"args": {"type": "dict"},
},
},
},
"connections": {"type": "dict"},
"dataid": {"type": "string"},
"layout": {"type": "list"},
"sidebar": {"type": "list"},
"title": {"type": "string"},
"subtitle": {"type": "string"},
}
descriptor_schema = {
"name": {"type": "string"},
"theme": {"type": "string", "regex": words_regex},
"theme_dict": {"type": "dict"},
"appbar": {
"type": "dict",
"schema": {
"title": {"type": "string"},
"subtitle": {"type": "string"},
"image": {"type": "string"},
},
},
"data": {"type": "dict"},
"show_help": {"type": "boolean"},
"pages": {
"type": "dict",
"allow_unknown": True,
"required": True,
"minlength": 1,
"keysrules": {"type": "string", "regex": bento_uid_regex},
"valuesrules": {"type": "dict", "schema": page_schema},
},
}