title: Bulk-insertion into couchbase via python
body: <p>I am trying to do some bulk-insertion in couch-base. I tried to search examples over SO and google, but I could not get any clue. Here someone mention that its not possible.</p>
  
  <p><a href="https://stackoverflow.com/questions/14742608/how-to-insert-a-documents-in-bulk-in-couchbase">How to insert a documents in bulk in Couchbase?</a> </p>
  
  <p>but I guess this question was asked 3 years ago. I search and if I understand correctly from below given link, its possible to insert document in bulk. </p>
  
  <p><a href="https://developer.couchbase.com/documentation/server/current/sdk/batching-operations.html" rel="nofollow noreferrer">https://developer.couchbase.com/documentation/server/current/sdk/batching-operations.html</a></p>
  
  <p><a href="https://pythonhosted.org/couchbase/api/couchbase.html#batch-operation-pipeline" rel="nofollow noreferrer">https://pythonhosted.org/couchbase/api/couchbase.html#batch-operation-pipeline</a></p>
  
  <p>Here is my code on which I want to implement bulk-insertion in couchbase</p>
  
  <pre><code>import time
  import csv
  from couchbase import Couchbase
  from couchbase.bucket import Bucket
  from couchbase.exceptions import CouchbaseError
  c = Bucket('couchbase://localhost/bulk-load')
  from couchbase.exceptions import CouchbaseTransientError
  BYTES_PER_BATCH = 1024 * 256 # 256K
  
  with open('/home/royshah/Desktop/bulk_try/roy.csv') as csvfile:
      lines = csvfile.readlines()[4:]
  for k, line in enumerate(lines):
      data_tmp = line.strip().split(',')
      strDate = data_tmp[0].replace("\"", "")
      timerecord = datetime.datetime.strptime(strDate,
                                             '%Y-%m-%d %H:%M:%S.%f')
      microsecs = timerecord.microsecond
      strDate = "\"" + strDate + "\""
      ts = calendar.timegm(timerecord.timetuple())*1000000 + microsecs
      datastore = [ts] + data_tmp[1:]
  
      stre = {'col1 ': datastore[1],  # I am making key-values on the fly from csv file
              'col2': datastore[2],
              'col3': datastore[3],
              'col4': datastore[4],
              'col5': datastore[5],
              'col6': datastore[6]}
    cb.upsert(str(datastore[0]), (stre))    # datastore[0] is used as document
                                        id and (stre) is used as key-value to be
                                        inserted for respective id. 
  </code></pre>
  
  <p>cb.upsert(str(datastore[0]), (stre)) 
     is doing single insertion and I want to make it bulk-insertion to make it faster. I had no idea how to turn this in bulk-insertion in couchbase. I find this example but not sure how to implement. </p>
  
  <p><a href="https://developer.couchbase.com/documentation/server/current/sdk/batching-operations.html" rel="nofollow noreferrer">https://developer.couchbase.com/documentation/server/current/sdk/batching-operations.html</a>    </p>
  
  <p>If someone point out some examples of bulk-load in couchbase or help me to figure out how can I do bulk-insertion via my code. I would be really really grateful. .thanx a lot for any idea or help.  </p>