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]#

Methods

__init__(**params)

instance(**params)

Create and return an instance of this class.

Attributes

name

param