Param
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
- breaking Version 2.3.0 raised the minimum supported Python version to 3.10 and removed several previously deprecated APIs. Code running on older Python versions or relying on removed APIs will break.
- breaking Version 2.2.0 removed deprecated APIs and changed warnings for unsafe operations into errors. Code that previously received warnings but continued to function might now raise exceptions.
- gotcha In version 2.3.2, the `Parameterized.__init__` docstring was removed because it shadowed user-defined class docstrings in IDEs like VSCode. While not breaking, developers relying on IDEs to show the `__init__` docstring might notice its absence.
- gotcha Version 2.3.1 fixed a regression in the `param.parameterized.edit_constant` context manager, which previously allowed class value mutation even when not constant. Users relying on this unintended behavior might see a change in mutation prevention.
Install
-
pip install param
Imports
- param
import param
- Parameterized
from param import Parameterized
Quickstart
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