Reputation: 2776
I'm trying to get a list of all the customers in my stripe account but am limited by pagination, wanted to know what the most pythonic way to do this.
customers = []
results = stripe.Customer.list(limit=100)
print len(results.data)
for c in results:
customers.append(c)
results = stripe.Customer.list(limit=100, starting_after=results.data[-1].id)
for c in results:
customers.append(c)
This lists the first 200, but then how do I do this if I have say 300, 500, etc customers?
Upvotes: 5
Views: 3052
Reputation: 17533
Stripe's Python library has an "auto-pagination" feature:
customers = stripe.Customer.list(limit=100)
for customer in customers.auto_paging_iter():
# Do something with customer
The auto_paging_iter
method will iterate over every customer, firing new requests as needed in the background until every customer has been retrieved.
The auto-pagination feature is documented here.
Upvotes: 12