The NumPy rate() function calculates the interest rate given the number of periodic payments, the payment amount or amounts, the present value, and the future value.
rate()