How to get the length of iterable got from PyObject_GetIter()?

You can not without consuming it.

You would need to use itertools.tee and iterate through one of them to find length (or a similar solution in C). There is a proposal for ilen Itertools.ilen(iterable), but it would consume the iterator (as it should).