add heartbeat callback API code and python wrapper