Param

2.3.3 · active · verified Sat Apr 11

Param is a zero-dependency Python library that enables the creation of classes with rich, declarative attributes (Parameter objects) for runtime validation, documentation, and serialization. It also provides a suite of expressive and composable APIs for reactive programming, allowing automatic updates on attribute changes and the declaration of complex reactive dependencies. Param is currently at version 2.3.3 and maintains a frequent release cadence with minor and patch updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining a `Parameterized` class with `Integer`, `String`, and `Event` parameters. It shows how to bind a method (`save_user_to_db`) to react to changes in the `submit` parameter using the `@param.depends` decorator. Changing parameter values and triggering the event causes the dependent method to execute.

import param

class UserForm(param.Parameterized):
    age = param.Integer(bounds=(0, None), doc='User age')
    name = param.String(doc='User name')
    submit = param.Event()

    @param.depends('submit', watch=True)
    def save_user_to_db(self):
        print(f'Saving user to db: name={self.name}, age={self.age}')

user = UserForm(name='Alice', age=30)
print(f'Initial user name: {user.name}, age: {user.age}')
user.submit = True # Triggers save_user_to_db

user.name = 'Bob'
user.age = 25
user.submit = True # Triggers save_user_to_db with new values

view raw JSON →