The Python KF code