Check the open source repo

Docker Couchbase Environment

Installation

Install libcouchbase on the Mac

brew install libcouchbase

Install libcouchbase on the Linux

CentOS

# Only needed during first-time setup:
wget http://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-6-x86_64.rpm
sudo rpm -iv couchbase-release-1.0-6-x86_64.rpm
# Will install or upgrade existing packages
sudo yum install libcouchbase-devel libcouchbase2-bin gcc gcc-c++

Ubuntu

# Only needed during first-time setup:
sudo wget -O - http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
# Adding Ubuntu 18.04 repo to apt/sources.list of 18.10 or 19.04
sudo echo "deb http://packages.couchbase.com/ubuntu bionic bionic/main" | sudo tee /etc/apt/sources.list.d/couchbase.list

# Will install or upgrade packages
sudo apt-get update
sudo apt-get install libcouchbase-dev libcouchbase2-bin build-essential

Create Python virutual env using virtualenv

Install packages

On the CentOS

yum install gcc gcc-c++ python-devel python-pip

On the Ubuntu

apt-get install build-essential python-dev python-pip

Install couchbase package using pip.

pip install couchbase==2.5.4

Sample Script in Python

One example

#!/usr/bin/python
# -*- coding: utf-8 -*-
import copy
import uuid
from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
from couchbase.views.iterator import View
from couchbase.views.params import Query
from couchbase.n1ql import N1QLQuery


# You should be able to connect to 
# the ips of the whole cluster from the maching running the script.
# Or you'll see error like

# *** couchbase.exceptions._TimeoutError_0x17 (generated, catch TimeoutError): <Key='12', RC=0x17[Client-Side timeout exceeded for operation. Inspect network conditions or increase the timeout], Operational Error, Results=1, C Source=(src/multiresult.c,316), Tracing Output={"12": {"s": "kv:Unknown", "i": 823564440, "b": "bucket_sample", "r": "172.42.92.71:11210", "t": 2500000}}>
cluster = Cluster('couchbase://couchbase_ip')
authenticator = PasswordAuthenticator('Administrator', 'password')
cluster.authenticate(authenticator)
cb = cluster.open_bucket('bucket_sample')

def main():
    # Example 1
    document = {
        "key": "value",
    }

    key = str(uuid.uuid4())
    cb.upsert(key, document)

    print(key)

    # Example 2
    # _design/beer
    for result in View(cb, "beer", "brewery_beers", full_set=True):
        cb.remove(result.docid)

    # Example 3
    q = Query(
        limit=limit,
        skip=skip,
        keys=["key"],
        inclusive_end=True
    )
    for result in View(cb, "docByModelName", "byModelName", include_docs=True, query=q):
        print(result.doc)

    # Example 4
    cb.n1ql_timeout = 3600
    q = N1QLQuery('SELECT * FROM default WHERE age = $age', age=22)
    for row in cb.n1ql_query(q):
        print row

if __name__ == "__main__":
    main()

An another example

def docs_iterator(cluster):
    cb = cluster.open_bucket('bucket')
    cb.timeout = 3600
    cb.views_timeout = 3600
    q = Query(
        key="Key",
        inclusive_end=True,
        full_set=True,
        connection_timeout=3600,
    )
    # When there are large amount of items,
    # the number of yield results could be less than it should be
    # due to short `views_timeout` and `connection_timeout` set.
    # Please keep them as large as possible.

    # _design/beer
    for result in View(cb, "beer", "brewery_beers", include_docs=True, query=q):
        # print(result.docid, result.doc)
        yield (result.docid, result.doc)

N1QL Examples

CREATE INDEX `index_name` ON `bucket`(`field_name`)

Reference