Skip to main content

json-paginator

PyPI Version License

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. Return None 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'])))

Metadata

Release files for json-paginator 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-paginator 0.1.0
File Size Uploaded Provenance Actions
json-paginator-0.1.0.tar.gz 1.8 kB Without provenance Details for json-paginator-0.1.0.tar.gz

Release files / json-paginator-0.1.0.tar.gz

Download URL json-paginator-0.1.0.tar.gz
Size 1.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a9f7242b9fcdb38815cfe30842963715a3eac46c102ff5560dedadb9ddad2681
BLAKE2b-256 checksum
How to use checksums
f9f01b8692954bb68fbaad537a09fc2ac61883d92f9666e6b7ccbc97611e3203
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

Security for json-paginator 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page