Class for creating numeric input parameter widgets that allow users to enter a single numeric value.This class can be imported from the squirrels.parameters or the squirrels module.
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).
Decorator for creating a simple numeric parameter that doesn’t involve user attributes or parent parameters.The body of the decorated function does not need to return anything (i.e., it can simply be pass).
The unique identifier for this parameter. Used to reference the parameter at query time (such as in context.py or when specifying parameter selections in the APIs).
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 NumberParameterOption objects.
The unique identifier for this parameter. Used to reference the parameter at query time (such as in context.py or when specifying parameter selections in the APIs).
A user attribute (like “access_level”) that determines which options are visible to different users. The decorated function should return options with matching user_groups values.To use custom user fields defined in pyconfigs/user.py, prefix with custom_fields. (e.g., "custom_fields.department").
The name of a parent parameter that controls which options are visible. The decorated function should return options with parent_option_ids matching the parent’s selected value.
Decorator for creating a parameter populated from a database table or query using a NumberDataSource.The decorated function must return a NumberDataSource object.
The unique identifier for this parameter. Used to reference the parameter at query time (such as in context.py or when specifying parameter selections in the APIs).
A user attribute that determines which options from the data source are visible to different users.To use custom user fields defined in pyconfigs/user.py, prefix with custom_fields..
This example uses decimal values for precise numeric input. Regardless of whether Decimal, float, or string values are used, the exact precision will always be maintained (without floating point errors).
Copy
from squirrels import parameters as pfrom decimal import Decimal@p.NumberParameter.create_simple( name="price_multiplier", label="Price Multiplier", min_value="0.1", max_value="2.0", increment=0.1, default_value=Decimal("1.2"), description="Enter price multiplier (0.1 to 2.0)")def price_multiplier_default(): pass
This example populates numeric constraints from a database query.
Copy
from squirrels import parameters as p, data_sources as ds@p.NumberParameter.create_from_source( name="inventory_quantity", label="Inventory Quantity", description="Enter quantity (based on current inventory)")def inventory_quantity_source() -> ds.NumberDataSource: return ds.NumberDataSource( table_or_query=""" SELECT AVG(quantity) AS default_value, MIN(quantity) AS min_value, MAX(quantity) AS max_value, 1 AS increment FROM inventory """, default_value_col="default_value", min_value_col="min_value", max_value_col="max_value", increment_col="increment" )
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).
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_value) is available to use for NumberParameter objects.