I think there is a helper function ``rotation_matrix`` in ``astropy.coordinates.angles`` that will do all this for you.