$k\cdot p$ effective Hamiltonian is important for theoretical analysis in condensed matter physics. Based on the 'kdotp-symmetry' package, we develop an upgraded package named 'kdotp-generator'. This generator takes in arbitrary magnetic symmetries with their representations and returns symmetry-allowed $k\cdot p$ Hamiltonians. Using this package, we calculate $k\cdot p$ Hamiltonians for irreducible corepresentations in 1651 magnetic space groups up to the third order, and their linear coupling to external fields including the electromagnetic field and the strain tensor. We hope that the package will facilitate related research in the future.