title: How can I use Python requests to paginate api calls with offset parameter
body: <p>I need to make repeated api calls as there is a limit on each call of 1000 records. There are about 20,000 total records of which I test them , keep a sample, then need request the next 1000. The offset parameter is available.</p>
  
  <pre><code>p = getpass.getpass()
  url = ("https://example.api.com/api/1.0/devices/all/?offset={}&amp;include_cols=asset_no,name,service_level,building&amp;type=physical" 
  r = requests.get(url, auth=HTTPBasicAuth('admin', p))
  data = json.loads(r.text)
  payload = data["Devices"]
  </code></pre>
  
  <p>offset value should increment by 1000 each api call, (ex. offset = 1000, offset = 2000, offset = 3000, etc) until all pages retrieved.</p>
  
  <p>How could I create a function that makes paginated api calls using this offset parameter? I believe a generator is what is needed, but I'm unable to understand the examples I've found, with the offset parameter I need to use. </p>