Skip to main content
Class for creating multi-select parameter widgets that allow users to choose multiple options from a list. This class can be imported from the squirrels.parameters or the squirrels module.

Factory methods

Factory methods are class methods that create and configure parameter instances. These methods are typically used in the pyconfigs/parameters.py file to create the parameter configurations (which describes the “shape” of the parameter but does not include the realtime user selections).

create_simple()

Decorator for creating a simple parameter from a function that returns select options. The decorated function must return a list of SelectParameterOption objects.

create_with_options()

Decorator for creating a parameter with options that can vary based on user attributes or parent parameter selections. The decorated function must return a list of SelectParameterOption objects. This is functionally equivalent to create_simple but with additional arguments available for user_attribute and parent_name.

create_from_source()

Decorator for creating a parameter populated from a database table or query using a SelectDataSource. The decorated function must return a SelectDataSource object.

Instance methods

Instance methods are available on parameter instances at query time (in context.py or data models) to retrieve selected values.

get_selected_list() -> Sequence[SelectParameterOption]

Gets the sequence of selected SelectParameterOption objects.
Sequence[SelectParameterOption]
A sequence of selected SelectParameterOption objects.

get_selected_list() -> Sequence[Any]

Gets the sequence of selected custom fields.
Sequence[Any]
A sequence of custom field values, or an empty sequence if no options are selected (unless none_is_all is True, in which case all options are returned).

get_selected_ids_as_list()

Gets the sequence of ID(s) of the selected option(s).
Sequence[str]
A sequence of ID strings of the selected options.

has_non_empty_selection()

Returns True if more than zero options were selected. False otherwise. Note that even when this returns False, all methods starting with “get_selected” would return the full list of options if none_is_all is set to True.
bool
True if at least one option is selected, False otherwise.

is_enabled()

Returns whether the parameter is enabled. A parameter is enabled if it has at least one selectable option.
bool
True if the parameter has at least one selectable option, False otherwise.

Examples for factory methods

All examples below are defined in the pyconfigs/parameters.py file.

Using create_simple for basic multi-select

For parameters that don’t need user-specific or parent-dependent options, you can use create_simple.

Cascading multi-select with parent dependency

This example shows how multi-select options can change based on a parent parameter selection.

User-specific multi-select options

This example shows different options based on user access levels.
If custom user fields are defined in pyconfigs/user.py, then they can be used to restrict visibility of parameter options as well. To do so, the user_attribute argument must be prefixed with custom_fields..

Multi-select from database source

This example populates multi-select options from a database table.

Cascading multi-select from database

This example shows a multi-select that depends on a parent parameter, both populated from database sources.

Examples for instance methods

Once parameters are configured, you can use instance methods in your models to access the selected values. The parameter instances are available through the context object (e.g., sqrl.prms).

Basic usage in context.py

Basic usage in Jinja SQL models

The following example works but is not recommended. See tip below for why.
To omit the WHERE clause entirely when no options are selected, you can do so as follows:
It is generally better to only use the instance methods in context.py to transform parameter selections into context variables. Using the instance methods directly in the data models is not recommended.IDEs can provide code suggestions for the available instance methods in Python instead of having to memorize which method (such as get_selected_ids_as_list) is available to use for MultiSelectParameter objects.

Accessing custom fields

Suppose you define a multi-select parameter with custom fields as such:
Then you can access the custom fields in context.py as follows: