The python KF code