param.ParameterizedFunction#

class param.ParameterizedFunction(*, name)[source]#

Acts like a Python function, but with arguments that are Parameters.

When a ParameterizedFunction is instantiated, it automatically calls its __call__ method and returns the result, acting like a Python function.

Features:

  • Declarative parameterization: Arguments are defined as Parameter objects, enabling type validation, bounds checking, and documentation.

  • Dynamic updates: Changes to parameters can dynamically influence the function’s behavior.

References

See https://param.holoviz.org/user_guide/ParameterizedFunctions.html

Notes

  • Subclasses of ParameterizedFunction must implement the __call__ method, which defines the primary functionality of the function.

  • The instance() method can be used to obtain an object representation of the class without triggering the function’s execution.

Examples

Define a subclass of ParameterizedFunction:

>>> import param
>>> class Scale(param.ParameterizedFunction):
...     multiplier = param.Number(default=2, bounds=(0, 10), doc="The multiplier value.")
...
...     def __call__(self, x):
...         return x * self.multiplier

Instantiating the parameterized function calls it immediately:

>>> result = Scale(5)
>>> result
10

Access the instance explicitly:

>>> scale3 = Scale.instance(multiplier=3)
>>> scale3.multiplier
3
>>> scale3(5)
15

Customize parameters dynamically:

>>> scale3.multiplier = 4
>>> scale3(5)
20

Parameter Definitions


__init__(**params)[source]#

Initialize a Parameterized instance with optional Parameter values.

Optional Parameter values must be supplied as keyword arguments (param_name=value), overriding their default values for this one instance. Any parameters not explicitly set will retain their defined default values.

If no name parameter is provided, the instance’s name attribute will default to an identifier string composed of the class name followed by an incremental 5-digit number.

Parameters:

**params – Optional keyword arguments mapping Parameter names to values.

Raises:

TypeError – If one of the keywords of params is not a Parameter name.

Examples

>>> import param
>>> class MyClass(param.Parameterized):
...     value = param.Number(default=10, bounds=(0, 20))
>>> obj = MyClass(value=15)

The value parameter is set to 15 for this instance, overriding the default.

Methods

__init__(**params)

Initialize a Parameterized instance with optional Parameter values.

instance(**params)

Create and return an instance of this class.

Attributes

name

param