We propose an efficient algorithm to construct k⋅p effective Hamiltonians, which is much faster than the previously proposed algorithms. This algorithm is implemented in MagneticKP package. The package applies to both single-valued (spinless) and double-valued (spinful) cases, and it works for both magnetic and nonmagnetic systems. By interfacing with SpaceGroupIrep or MSGCorep packages, it can directly output the k⋅p Hamiltonian around arbitrary momentum and expanded to arbitrary order in k.