Handle paginated list responses
masterList methods in the Telnyx API are paginated. The library provides auto-paginating iterators that fetch subsequent pages automatically as you iterate.
Synchronous Auto-pagination
from telnyx import Telnyx
client = Telnyx()
all_access_ip_addresses = []
for access_ip_address in client.access_ip_address.list(
page_number=1,
page_size=50,
):
all_access_ip_addresses.append(access_ip_address)Asynchronous Auto-pagination
import asyncio
from telnyx import AsyncTelnyx
client = AsyncTelnyx()
async def main() -> None:
all_access_ip_addresses = []
async for access_ip_address in client.access_ip_address.list(
page_number=1,
page_size=50,
):
all_access_ip_addresses.append(access_ip_address)
print(all_access_ip_addresses)
asyncio.run(main())Granular Page Control
You can also manually control pagination using .has_next_page(), .next_page_info(), or .get_next_page().
# Manual page control example
first_page = await client.access_ip_address.list(
page_number=1,
page_size=50,
)
if first_page.has_next_page():
print(f"will fetch next page using these details: {first_page.next_page_info()}")
next_page = await first_page.get_next_page()
print(f"number of items we just fetched: {len(next_page.data)}")