跳转到主要内容

用于遍历分页JSON API响应的生成器

项目描述

json-paginator

PyPI Version License

用于遍历分页JSON API响应的生成器

安装

pip install json-paginator

用法

使用以下方式实例化 JsonApiPaginator

  • API输出的第1页的URL
  • 一个函数(或lambda) get_nextpage(url, body),它描述如何获取下一页。返回 None 以停止迭代。

示例

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'])))

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

json-paginator-0.1.0.tar.gz (1.8 kB 查看哈希值)

上传时间: 源代码

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面