<jupyter_start><jupyter_text>Introduction **Param is a library providing Parameters:**Python attributes extended to have features such as* type and range checking* dynamically generated values* documentation strings* default values* events**Param enables you to write robust and powerful applications in just a few lines of code**.**Param  is free, open source, small, and has no external dependencies**, so that it can easily be included as part of other projects.  Example: A Parameterized Class The [Pythagorean Theorem](https://en.wikipedia.org/wiki/Pythagorean_theorem) is one of the world's most famous equations.**We will illustrate how powerful Param is** by building a model of the Pythagorean Theorem.  **Pythagorean Theorem Class**<jupyter_code>import param, math, time
class PythagoreanTheorem(param.Parameterized):
    """Model of the Pythagorean Theorem"""

    a = param.Number(default=0, bounds=(0,None), doc="Length of side a")
    b = param.Number(default=0, bounds=(0,None), doc="Length of side b")
    c = param.Number(default=0, bounds=(0,None), doc="Length of the hypotenuse c",
                     constant=True)


    def __init__(self, **params):
        super().__init__(**params) # Sets values a and b if provided in the params
        
        self._update_hypotenuse() # Sets the value c


    @param.depends("a", "b", watch=True) # Triggers a run of the function whenever a or b is changed
    def _update_hypotenuse(self):
        """Updates the length of the hypotenuse"""
        with param.edit_constant(self):
            self.c = math.sqrt(self.a**2+self.b**2)<jupyter_output><empty_output><jupyter_text>**Pythagorean Theorem Object** **Lets try to use the model**<jupyter_code>pythagoras = PythagoreanTheorem(a=3, b=4)     # create an object with initial values for the parameters a and b
pythagoras.c                                  # print the result for c<jupyter_output><empty_output><jupyter_text>**Using the Parameters** We will now **take a closer look** at what these few lines of code provide us:  **Param Provides Parameter Validation**<jupyter_code># check admissible parameter values
try:
    pythagoras1 = PythagoreanTheorem(a=-1, b=4)
except Exception as ex:
    print(ex)
# check parameter types
try:
    pythagoras2 = PythagoreanTheorem(a="length is 3", b=4)
except Exception as ex:
    print(ex)<jupyter_output><empty_output><jupyter_text>Param contains a wide range of useful parameter types, including* `String`* `Integer`* `Float`* `Bool`* `DataFrame`  **Param Provides Constant Parameters**<jupyter_code># constant values cannot be changed
try:
    pythagoras.c = 3
except Exception as ex:
    print(ex)<jupyter_output><empty_output><jupyter_text>**Param Provides Default Values**<jupyter_code>print( f"{pythagoras.param.a.name} = {pythagoras.param.a.default}")<jupyter_output><empty_output><jupyter_text>**Param Provides Documentation**<jupyter_code>?pythagoras
# more extensive documentation
help(pythagoras)<jupyter_output><empty_output><jupyter_text>**Param Provides Events** You can **use events to react to parameter changes.** We have already reacted to events by using the `@param.depends("a", "b", watch=True)` annotation$\quad$ to react to `a` or `b` changing by updating the calculated hypotenuse.Here we will use the alternative **`param.watch`** to just watch for changes to the hypotenuse `c` and print the event raised.<jupyter_code>def print_event(event):
    print(event, end='\n\n')

watcher = pythagoras.param.watch(print_event, "c")
for _ in range(3):
    pythagoras.b += 1
    time.sleep(1)<jupyter_output><empty_output><jupyter_text>We can also **stop watching** again:<jupyter_code>pythagoras.param.unwatch(watcher)<jupyter_output><empty_output><jupyter_text>**Param Makes it Easy to Create GUIs** On top of param you can **quickly build interactive applications and graphical user interfaces.** The whole [HoloViz](https://holoviz.org) ecosystem is built in this way!                                     Let's use **[Panel](https://panel.holoviz.org/) to illustrate how powerful this is.**<jupyter_code>import panel as pn
pn.extension()
pn.Param(pythagoras)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10980580196595541, 'fraction_numerical': 0.004795013186286262, 'mean_word_length': 4.900990099009901, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '227456', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1264, 'n_words': 410, 'path': 'examples/Promo.ipynb', 'repo_name': 'ektar/param', 'size': '4171'}