A generator for iterating over paginated JSON API responses
Project description
json-paginator
A generator for iterating over paginated JSON API responses
Installation
pip install json-paginator
Usage
Instantiate JsonApiPaginator
with:
- A URL to page 1 of the API output
- A function (or lambda)
get_nextpage(url, body)
which describes how to get the next page. ReturnNone
to stop iteration.
Example:
from json_paginator import JsonApiPaginator
BASE = 'https://galaxy.ansible.com'
def get_next_page(url, body):
if body['next_link']:
return BASE + body['next_link']
return None
# instantiate the paginator
pages = JsonApiPaginator(
BASE + '/api/v1/categories/?page=1',
get_next_page
)
# iterate over the pages
for url, body in pages:
print("calling %s" % (url))
print("found %s results" % (len(body['results'])))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
json-paginator-0.1.0.tar.gz
(1.8 kB
view hashes)