title: Is there a way to form batched requests using python requests module ? I want to send multiple homogenous http API requests in a single POST request
body: <p>Is there a way to form batched requests using python requests module ? I want to send multiple homogenous http API requests in a single POST request. I am trying to use the GCP documentation <a href="https://cloud.google.com/dns/docs/reference/batch?hl=en_US&amp;_ga=2.138235123.-2126794010.1660759555" rel="nofollow noreferrer">https://cloud.google.com/dns/docs/reference/batch?hl=en_US&amp;_ga=2.138235123.-2126794010.1660759555</a> to create multiple DNS records in a single POST request. Can anyone help with a simple example of how this could be achieved using python requests module ?</p>
  <p>This is how the sample POST request will look like:</p>
  <pre><code>POST /batch/farm/v1 HTTP/1.1
  Authorization: Bearer your_auth_token
  Host: www.googleapis.com
  Content-Type: multipart/mixed; boundary=batch_foobarbaz
  Content-Length: total_content_length
  
  --batch_foobarbaz
  Content-Type: application/http
  Content-ID: &lt;item1:12930812@barnyard.example.com&gt;
  
  GET /farm/v1/animals/pony
  
  --batch_foobarbaz
  Content-Type: application/http
  Content-ID: &lt;item2:12930812@barnyard.example.com&gt;
  
  PUT /farm/v1/animals/sheep
  Content-Type: application/json
  Content-Length: part_content_length
  If-Match: &quot;etag/sheep&quot;
  
  {
    &quot;animalName&quot;: &quot;sheep&quot;,
    &quot;animalAge&quot;: &quot;5&quot;
    &quot;peltColor&quot;: &quot;green&quot;,
  }
  
  --batch_foobarbaz
  Content-Type: application/http
  Content-ID: &lt;item3:12930812@barnyard.example.com&gt;
  
  GET /farm/v1/animals
  If-None-Match: &quot;etag/animals&quot;
  
  --batch_foobarbaz--
  </code></pre>
  <p>Basically; the main intention here is to not overload the remote API with multiple http requests causing the rate limit throttling but instead use batched http requests so that the remote API gets only a single batched request embedded with multiple requests in the form of parts.</p>