implemented handle wrapping logic for python bindings.