Param

Declarative Python programming using Parameters

View the Project on GitHub ioam/param

What is a Parameter?

A Parameter is a special type of Python attribute extended to have features such as type and range checking, dynamically generated values, documentation strings, default values, etc., each of which is inherited from parent classes if not specified in a subclass.

>>> import param,random
>>> class A(param.Parameterized):
...    a = param.Number(0.5,bounds=(0,1),doc="Probability that...")
...    b = param.Boolean(False,doc="Enable feature...")
... 
>>> class B(A):
...    b = param.Boolean(True)
... 
>>> x = B(a=lambda: random.uniform(0,1))
>>> x.a
0.37053399325641945
>>> x.a
0.64907392300071842

Parameters provide optional range and type checking

>>> x.a=5
[...]
ValueError: Parameter 'a' must be at most 1
>>> x.a="0.5"
[...]
ValueError: Parameter 'a' only takes numeric values

Parameters have docstrings

>>> help(x)
[...]
class B(A)
[...]
|  Data descriptors defined here:
|  b
|      Enable feature...
[...]
|  Data descriptors inherited from A:
|  a
|      Probability that...

Param is lightweight

Param consists of two BSD-licensed Python files, with no dependencies outside of the standard library.

Parameters make GUI programming simpler

Parameters make it simple to generate GUIs. An interface for Tk already exists (http://ioam.github.com/paramtk/), providing a property sheet that can automatically generate a GUI window for viewing and editing an object's Parameters.

Installation

Official releases of Param are available at PyPi, and can be installed via pip install --user param or easy_install param. More recent changes can be obtained by cloning the git repository.

Reference Manual

Comprehensive reference generated from the source code:
Reference Manual

Support

Questions and comments are welcome at https://github.com/ioam/param/issues.