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?
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 (you have to scroll down a bit).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With