Skip to content

Variables

Variables that YAML specs and pipelines can reference.

lumen.variables

disallow_refs = {'allow_refs': False} if param2 else {} module-attribute

state = _session_state() module-attribute

Constant

Bases: Variable

Constant declares a constant value that can be referenced.

variable_type = 'constant' class-attribute

Cookie

Bases: Variable

Cookie variables reflect the value of a cookie in the request.

key = param.String(default=None, constant=True, doc='\n The cookie to observe.') class-attribute instance-attribute

value = pn.state.cookies.get(key, self.default) instance-attribute

variable_type = 'cookie' class-attribute

EnvVariable

Bases: Variable

EnvVariable fetches an environment variable that can be referenced.

key = param.String(default=None, constant=True, doc='\n The name of the environment variable to observe.') class-attribute instance-attribute

value = os.environ[key] instance-attribute

variable_type = 'env' class-attribute

Header

Bases: Variable

Header variables reflect the value of a request header.

key = param.String(default=None, constant=True, doc='\n The request header to observe.') class-attribute instance-attribute

value = pn.state.headers.get(key, self.default) instance-attribute

variable_type = 'header' class-attribute

MultiTypeComponent

Bases: Component

MultiComponentType is the baseclass for extensible Lumen components.

A MultiTypeComponent can be resolved using the _get_type method either by the name declared in the <component>_type attribute, where the name of the component represent the immediate subclasses of MultiTypeComponent. For example class View(MultiTypeComponent) should define view_type for all its descendants to override.

Just as any other Component, MultiTypeComponent implements methods to construct an instance from a specification, export the specification of a component and the ability to validate a component.

from_spec(spec) classmethod

to_spec(context=None)

Exports the full specification to reconstruct this component.

Returns:

Type Description
Resolved and instantiated Component object

validate(spec, context=None) classmethod

Validates the component specification given the validation context and the path.

Arguments

spec: dict | str The specification for the component being validated or a reference to the component. context: dict Validation context contains the specification of all previously validated components, e.g. to allow resolving of references.

Returns:

Type Description
Validated specification.

Parameter

Bases: Variable

Parameter variables reflect the current value of a parameter.

parameter = param.ClassSelector(class_=(param.Parameter), constant=True, **disallow_refs, doc='\n A parameter instance whose current value will be reflected\n on this variable.') class-attribute instance-attribute

variable_type = 'param' class-attribute

URLQuery

Bases: Variable

URLQuery variables reflect the value of a URL query parameter.

key = param.String(default=None, constant=True, doc='\n The URL query parameter to observe.') class-attribute instance-attribute

value = pn.state.session_args[key][0].decode('utf-8') instance-attribute

variable_type = 'url' class-attribute

UserInfo

Bases: Variable

UserInfo variables reflect a value in the user info returned by an OAuth provider.

key = param.String(default=None, constant=True, doc='\n The key in the OAuth pn.state.user_info dictionary to observe.') class-attribute instance-attribute

value = pn.state.user_info.get(key, self.default) instance-attribute

variable_type = 'user' class-attribute

Variable

Bases: MultiTypeComponent

Variable components declare values that can be referenced from other components.

The source of the Variable value can be anything from an environment variable to a widget or URL parameter. Variable components allow a concise way to configure other components and make it possible to orchestrate actions across multiple components.

default = param.Parameter(constant=True, doc='\n Default value to use if no other value is defined') class-attribute instance-attribute

label = param.String(default=None, doc='\n Optional label override for variable. Used wherever the variable\n shows up in the UI.') class-attribute instance-attribute

materialize = param.Boolean(default=False, constant=True, doc='\n Whether the variable should be inlined as a constant variable\n (in the Lumen Builder).') class-attribute instance-attribute

panel property

Optionally returns a renderable component that allows controlling the variable.

required = param.Boolean(default=False, constant=True, doc='\n Whether the variable should be treated as required.') class-attribute instance-attribute

secure = param.Boolean(default=False, constant=True, doc='\n Whether the variable should be treated as secure.') class-attribute instance-attribute

value = param.Parameter(doc='\n The materialized value of the variable.') class-attribute instance-attribute

variable_type = None class-attribute

as_materialized()

If the variable is to be materialized by the builder this implements the conversion from a variable that references some external value to a materialized value.

from_spec(spec, variables=None) classmethod

Variables

Bases: Parameterized

Variables stores a number Variable types and mirrors their values onto dynamically created parameters allowing other components to easily watch changes in a variable.

add_variable(var)

Adds a new variable to the Variables instance and sets up a parameter that can be watched.

Arguments

var: Variable | panel.widgets.Widget | param.Parameter The Variable to add to the Variables store.

create_variables() classmethod

from_spec(spec) classmethod

keys()

panel(variables=None)

Widget

Bases: Variable

Widget variables dynamically reflect the current widget value.

kind = param.String(default=None, constant=True, doc='\n The type of widget to instantiate.') class-attribute instance-attribute

panel property

throttled = param.Boolean(default=True, constant=True, doc='\n If the widget has a value_throttled parameter use that instead,\n ensuring that no intermediate events are generated, e.g. when\n dragging a slider.') class-attribute instance-attribute

value = self._widget.value instance-attribute

variable_type = 'widget' class-attribute

to_spec(context=None)

Exports the full specification to reconstruct this component.

Returns:

Type Description
Resolved and instantiated Component object

is_ref(value)

Whether the value is a reference.

resolve_module_reference(reference, component_type=None)

base

Constant

Bases: Variable

Constant declares a constant value that can be referenced.

variable_type = 'constant' class-attribute

Cookie

Bases: Variable

Cookie variables reflect the value of a cookie in the request.

key = param.String(default=None, constant=True, doc='\n The cookie to observe.') class-attribute instance-attribute
value = pn.state.cookies.get(key, self.default) instance-attribute
variable_type = 'cookie' class-attribute

EnvVariable

Bases: Variable

EnvVariable fetches an environment variable that can be referenced.

key = param.String(default=None, constant=True, doc='\n The name of the environment variable to observe.') class-attribute instance-attribute
value = os.environ[key] instance-attribute
variable_type = 'env' class-attribute

Header

Bases: Variable

Header variables reflect the value of a request header.

key = param.String(default=None, constant=True, doc='\n The request header to observe.') class-attribute instance-attribute
value = pn.state.headers.get(key, self.default) instance-attribute
variable_type = 'header' class-attribute

Parameter

Bases: Variable

Parameter variables reflect the current value of a parameter.

parameter = param.ClassSelector(class_=(param.Parameter), constant=True, **disallow_refs, doc='\n A parameter instance whose current value will be reflected\n on this variable.') class-attribute instance-attribute
variable_type = 'param' class-attribute

URLQuery

Bases: Variable

URLQuery variables reflect the value of a URL query parameter.

key = param.String(default=None, constant=True, doc='\n The URL query parameter to observe.') class-attribute instance-attribute
value = pn.state.session_args[key][0].decode('utf-8') instance-attribute
variable_type = 'url' class-attribute

UserInfo

Bases: Variable

UserInfo variables reflect a value in the user info returned by an OAuth provider.

key = param.String(default=None, constant=True, doc='\n The key in the OAuth pn.state.user_info dictionary to observe.') class-attribute instance-attribute
value = pn.state.user_info.get(key, self.default) instance-attribute
variable_type = 'user' class-attribute

Variable

Bases: MultiTypeComponent

Variable components declare values that can be referenced from other components.

The source of the Variable value can be anything from an environment variable to a widget or URL parameter. Variable components allow a concise way to configure other components and make it possible to orchestrate actions across multiple components.

default = param.Parameter(constant=True, doc='\n Default value to use if no other value is defined') class-attribute instance-attribute
label = param.String(default=None, doc='\n Optional label override for variable. Used wherever the variable\n shows up in the UI.') class-attribute instance-attribute
materialize = param.Boolean(default=False, constant=True, doc='\n Whether the variable should be inlined as a constant variable\n (in the Lumen Builder).') class-attribute instance-attribute
panel property

Optionally returns a renderable component that allows controlling the variable.

required = param.Boolean(default=False, constant=True, doc='\n Whether the variable should be treated as required.') class-attribute instance-attribute
secure = param.Boolean(default=False, constant=True, doc='\n Whether the variable should be treated as secure.') class-attribute instance-attribute
value = param.Parameter(doc='\n The materialized value of the variable.') class-attribute instance-attribute
variable_type = None class-attribute
as_materialized()

If the variable is to be materialized by the builder this implements the conversion from a variable that references some external value to a materialized value.

from_spec(spec, variables=None) classmethod

Variables

Bases: Parameterized

Variables stores a number Variable types and mirrors their values onto dynamically created parameters allowing other components to easily watch changes in a variable.

add_variable(var)

Adds a new variable to the Variables instance and sets up a parameter that can be watched.

Arguments

var: Variable | panel.widgets.Widget | param.Parameter The Variable to add to the Variables store.

create_variables() classmethod
from_spec(spec) classmethod
keys()
panel(variables=None)

Widget

Bases: Variable

Widget variables dynamically reflect the current widget value.

kind = param.String(default=None, constant=True, doc='\n The type of widget to instantiate.') class-attribute instance-attribute
panel property
throttled = param.Boolean(default=True, constant=True, doc='\n If the widget has a value_throttled parameter use that instead,\n ensuring that no intermediate events are generated, e.g. when\n dragging a slider.') class-attribute instance-attribute
value = self._widget.value instance-attribute
variable_type = 'widget' class-attribute
to_spec(context=None)

Exports the full specification to reconstruct this component.

Returns:

Type Description
Resolved and instantiated Component object