from traitlets import Int class MyClass: my_attr = Int() obj = MyClass() obj.my_attr = 'abc'
from traitlets import Unicode, TraitError def validate_length(value): if len(value) < 5: raise TraitError('String must be at least 5 characters long') class MyClass: my_attr = Unicode(validate=validate_length) obj = MyClass() obj.my_attr = 'abc'Package Library: traitlets.