LinkedIn Reddit icon

Dunder Doc

by Valdir Stumm Jr

Handling Headers-Based Pagination on APIs with Python

The other day I was building a Python script to fetch some information about all my repositories on GitHub. Their API is pretty straightforward and well documented. Fetching my repos was as simple as: >>> import requests >>> response = requests.get("https://api.github.com/users/stummjr/repos") The thing is that such request gave me a list with all my repos on it. No info on pagination whatsoever on the response body. After a bit of research, I found out that GitHub APIs take advantage of the Link header to expose several pagination options.