> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pysquirrels.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NumberRangeParameterOption

> Parameter option for number range widgets

Parameter option for number range parameters that can vary based on selection of another parameter.

This class can be imported from the `squirrels.parameter_options` or the `squirrels` module.

## Constructor

Creates a `NumberRangeParameterOption` object. Typically used in `pyconfigs/parameters.py`.

```python theme={null}
def __init__(
    self, min_value: decimal.Decimal | int | float | str, 
    max_value: decimal.Decimal | int | float | str, 
    *, increment: decimal.Decimal | int | float | str = 1, 
    default_lower_value: decimal.Decimal | int | float | str | None = None, 
    default_upper_value: decimal.Decimal | int | float | str | None = None, 
    user_groups: Iterable[Any] | str = frozenset(), 
    parent_option_ids: Iterable[str] | str = frozenset()
) -> None:
```

<Expandable title="arguments" defaultOpen>
  <ResponseField name="min_value" type="decimal.Decimal | int | float | str" required>
    Minimum selectable value for both lower and upper values. Can be provided as a Decimal, int, float, or string representation of a number.
  </ResponseField>

  <ResponseField name="max_value" type="decimal.Decimal | int | float | str" required>
    Maximum selectable value for both lower and upper values. Can be provided as a Decimal, int, float, or string representation of a number.

    Must be greater than or equal to `min_value`.
  </ResponseField>

  <ResponseField name="increment" type="decimal.Decimal | int | float | str" default="1">
    Increment or step value for the number range input. Must fit evenly between `min_value` and `max_value`. Can be provided as a Decimal, int, float, or string representation of a number.

    Must fit evenly between `min_value` and `max_value`. Increment must be specified if the difference is not divisible by 1.
  </ResponseField>

  <ResponseField name="default_lower_value" type="decimal.Decimal | int | float | str | None" default="None">
    Default lower value for this option. Must be selectable based on `min_value`, `max_value`, and `increment`. Can be provided as a Decimal, int, float, string representation of a number, or None. If None, defaults to `min_value`.
  </ResponseField>

  <ResponseField name="default_upper_value" type="decimal.Decimal | int | float | str | None" default="None">
    Default upper value for this option. Must be selectable based on `min_value`, `max_value`, and `increment`. Can be provided as a Decimal, int, float, string representation of a number, or None. If None, defaults to `max_value`.

    Must be greater than or equal to `default_lower_value`.
  </ResponseField>

  <ResponseField name="user_groups" type="Iterable[Any] | str" default="frozenset()">
    User group(s) this option is visible for. Only applies if `user_attribute` is provided to the factory method `create_with_options` associated to the [NumberRangeParameter](/references/python/parameters/numberrangeparameter).
  </ResponseField>

  <ResponseField name="parent_option_ids" type="Iterable[str] | str" default="frozenset()">
    Parent option id(s) that must be selected for this option to be visible. Only applies if `parent_name` is provided to the factory method `create_with_options` associated to the [NumberRangeParameter](/references/python/parameters/numberrangeparameter).
  </ResponseField>
</Expandable>

## Examples

A `NumberRangeParameterOption` object is created in the `pyconfigs/parameters.py` file. It must be created in a function decorated with the `create_with_options` factory method from [NumberRangeParameter](/references/python/parameters/numberrangeparameter).

### Usage example in parameters.py

```python highlight="10-15" theme={null}
from squirrels import parameters as p, parameter_options as po

@p.NumberRangeParameter.create_with_options(
    name="price_range", 
    label="Price Range",
    description="Price range for filtering products"
)
def price_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=0,
            max_value=1000,
            default_lower_value=0,
            default_upper_value=100
        )
    ]
```

In addition, the following are some additional examples for creating a `NumberRangeParameterOption` object.

### Setting up cascading parameters with varying number ranges

This example shows how to create number range options that change their constraints based on the selection of a parent parameter (e.g., different product categories with different price ranges).

```python highlight="18,28,36" theme={null}
# Parent parameter for product category
@p.SingleSelectParameter.create_with_options(
    name="product_category", 
    label="Product Category",
    description="Category of products"
)
def product_category_options():
    return [
        po.SelectParameterOption(id="electronics", label="Electronics"),
        po.SelectParameterOption(id="furniture", label="Furniture"),
    ]

# Child number range parameter with ranges that vary by category
@p.NumberRangeParameter.create_with_options(
    name="price_range", 
    label="Price Range",
    description="Price range based on product category",
    parent_name="product_category"  # Name of the parent parameter above
)
def price_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=0, 
            max_value=2000,
            increment=10,
            default_lower_value=50,
            default_upper_value=500,
            parent_option_ids="electronics"  # Only applies when "electronics" is selected
        ),
        po.NumberRangeParameterOption(
            min_value=0, 
            max_value=10000,
            increment=10,
            default_lower_value=100,
            default_upper_value=1000,
            parent_option_ids="furniture"  # Only applies when "furniture" is selected
        )
    ]
```

### Restricting value ranges by user groups

This example shows how to provide different value range constraints based on user access levels using the `user_groups` parameter.

```python highlight="5,15,23" theme={null}
@p.NumberRangeParameter.create_with_options(
    name="salary_range", 
    label="Salary Range",
    description="Salary range for search",
    user_attribute="access_level"
)
def salary_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=20000,
            max_value=80000,
            increment=1000,
            default_lower_value=30000,
            default_upper_value=60000,
            user_groups=["member"]  # Members see limited salary range
        ),
        po.NumberRangeParameterOption(
            min_value=20000,
            max_value=500000,
            increment=1000,
            default_lower_value=30000,
            default_upper_value=100000,
            user_groups=["admin"]  # Admins see full salary range
        )
    ]
```

If custom user fields are defined in `pyconfigs/user.py`, then they can be used to restrict value range constraints as well. To do so, the `user_attribute` argument must be prefixed with `custom_fields.`.

```python highlight="5,14,21" theme={null}
@p.NumberRangeParameter.create_with_options(
    name="commission_range", 
    label="Commission Range",
    description="Commission range as percentage",
    user_attribute="custom_fields.department"
)
def commission_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=0,
            max_value=10,
            default_lower_value=1,
            default_upper_value=5,
            user_groups=["sales"]  # Sales team sees standard commission range
        ),
        po.NumberRangeParameterOption(
            min_value=0,
            max_value=50,
            default_lower_value=0,
            default_upper_value=15,
            user_groups=["executive"]  # Executives see full commission range
        )
    ]
```
