Skip to main content
Data source class for populating number parameter options from a database table or query. This class can be imported from the squirrels.data_sources or the squirrels module.

Constructor

Creates a NumberDataSource object.
def __init__(
    self, table_or_query: str, min_value_col: str, max_value_col: str, 
    *, increment_col: str | None = None, default_value_col: str | None = None, 
    id_col: str | None = None, source: SourceEnum = SourceEnum.CONNECTION, 
    user_group_col: str | None = None, parent_id_col: str | None = None, 
    connection: str | None = None
) -> None:

Examples

A NumberDataSource object is created in the pyconfigs/parameters.py file. It must be created in a function decorated with the create_from_source factory method from NumberParameter.

Usage example in parameters.py

from squirrels import parameters as p, data_sources as ds

@p.NumberParameter.create_from_source(
    name="top_n", 
    label="Top N Records",
    description="Number of top records to display"
)
def top_n_source():
    return ds.NumberDataSource(
        table_or_query="""
            SELECT 
                1 AS min_val,
                100 AS max_val,
                5 AS increment,
                10 AS default_val
        """,
        min_value_col="min_val",
        max_value_col="max_val",
        increment_col="increment",
        default_value_col="default_val"
    )
In addition, the following are some additional examples for creating a NumberDataSource object.

Using a table from a specific connection

This example uses a table called “parameter_configs” from the “config_db” connection.
ds.NumberDataSource(
    table_or_query="parameter_configs",
    min_value_col="min_threshold",
    max_value_col="max_threshold",
    default_value_col="default_threshold",
    connection="config_db"
)
The connection must either be defined in squirrels.yml or the connections.py file.

Using seeds as the data source

This example uses a seed file called “number_config”.
ds.NumberDataSource(
    table_or_query="number_config",
    min_value_col="min_value",
    max_value_col="max_value",
    source=ds.SourceEnum.SEEDS
)

Enabling cascading effects with a parent parameter

In this example, the minimum, maximum, and default values are determined by the selected value of another parameter called “metric_type”.
@p.NumberParameter.create_from_source(
    name="threshold_value", 
    label="Threshold Value",
    description="The threshold for the selected metric",
    parent_name="metric_type"
)
def threshold_value_source():
    return ds.NumberDataSource(
        table_or_query="metric_thresholds",
        min_value_col="min_threshold",
        max_value_col="max_threshold",
        increment_col="step_size",
        default_value_col="default_threshold",
        parent_id_col="metric_type_id"  # Cascades based on metric_type selection
    )