Augment is a package that provides Python decorators for contracts and augmenting OOP. Contracts The syntax below should be self explanatory. It can be applied both to bound and unbound methods. # Constraints on passed arguments. # Constraints can be callables or regular expressions. # Throws a `TypeError` by default if contraints are violated. # Optionally, an error handler can be specified which receives the errors. @ensure_args(a=lambda x: x > 10, b=r'^?-\d+(\.\d+)$', c=lambda x: x 10, b=lambda x: hasattr(x, '__getitem__'), c=lambda x: x Function/method hooks Basic function hooks to run on entering, leaving or both ways. def login(root): print "Logging in." def logout(root): print "Logging out" # `login` will run before entering `home`. # `logout` will run after exiting from `home`. # `root` param passed to `home` will be passed to `login`, `logout`. @enter(login) @leave(logout) def home(root): print "Home page." def tracer(): print "tracing" # `tracer` will run both before entering `home` and after # exiting `home`. @around(tracer) def inbox(): print "Inbox" Please note that the hooks(`login` and `logout`) above are passed the arguments passed to the wrapped method(`home`). Method hooks should be accepting the same arguments as wrapped method. They work the same on bound functions. class Foo: def login(self): print "Logging in." def logout(self): print "Logging out" @leave(logout) @enter(login) def home(self, test=None): print "Home page." def tracer(self): print "tracing" @around(tracer) def inbox(self): print "Inbox" Dynamic delgation class Foo: def __init__(self): self.a = 'a' self.b = 'b' self.c = 'c' @delegate_to('foo_delegate', 'a', 'b') class Bar: def __init__(self): self.foo_delegate = Foo() b = Bar() # `a` and `b` will be delegated to `Foo`. print b.a print b.b # This will throw an AttributeError. print b.c Requirements: