title: Python async API requests in batches
body: <p>I m tryin to make async API calls this way:</p>
  <ol>
  <li>func to send request:</li>
  </ol>
  <blockquote>
  <pre><code>async def get_data(client, postdata):
      res = await client.post(url=_url, headers=_headers, data=postdata)
  
      return res
  </code></pre>
  </blockquote>
  <ol start="2">
  <li>func to parse JSON:</li>
  </ol>
  <blockquote>
  <pre><code>async def parse_res(client, postdata):
      
      res = await get_data(client, postdata)
      
      if bool(json.loads(res.text)['suggestions']):
          _oks = &lt;...grab some JSON fields...&gt;
      else:
          _oks = {}
      return _oks
  </code></pre>
  </blockquote>
  <ol start="3">
  <li>I wrap this two funcs in MAIN():</li>
  </ol>
  <blockquote>
  <pre><code>async def main(_jobs):
      
      async with httpx.AsyncClient() as client:
          
          batch = []
          calls = []
      
          for job in _jobs:
  
              _postdata = '{ &quot;query&quot;: &quot;'+ job + '&quot; }'
  
              calls.append(asyncio.create_task(parse_res(client, _postdata)))
              
          batch = await asyncio.gather(*calls)
              
          return batch
  </code></pre>
  </blockquote>
  <p>and then just run MAIN()</p>
  <p>But the API can handle about 30-50 fast (nearly simultaneous requests or throws 429 HTTP error).</p>
  <p>So i need to send batches of 30 calls and process 10 000 requests in chunks.</p>
  <p>How do i process 10 000 (ten thousand) API calls in batches of 30 ?</p>