Created
February 23, 2018 02:54
-
-
Save fermayo/9d0706ccbefe7425c643ee0c271d949b to your computer and use it in GitHub Desktop.
Little function to repaginate APIs that use 'Link' headers (i.e. GitHub API v3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def depaginate(initial_url, **kwargs): | |
r = requests.get(initial_url, **kwargs) | |
r.raise_for_status() | |
yield r.json() | |
while r.links.get('next'): | |
r = requests.get(r.links.get('next'), **kwargs) | |
r.raise_for_status() | |
yield r.json() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment