Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History

Proposed Python SDK API

This is about designing the API for the next generation Python SDK for Couchbase. In the end the API might look the same as the current one, or be completely different. Feel free to come up with any ideas.

To make it easier to get a feeling on what the API might look like I'll list a few API calls from different SDKs.

"Python" describes the current API, "Python vmx" is what Volker Mische has in mind. Add your own ideas, leave comments or sent an email to the Couchbase Group.

Connect to a bucket

The Python has the concept of a Server Connection where you can select buckets from. In the Ruby and PHP you connect directly to a bucket.


couchbase = Couchbase(ip:port, username, password)
bucket = couchbase[bucketname]

Python vmx

Following the way Ruby is doing it, keeping the bucket concept, but different from the old Python API.

cb = Couchbase.connect(ip:port, username, password, bucket)

The connect will be an instance of the Bucket class. This way the API can be expanded in the future to do administrative tasks on the cluster that are not bucket specific.


In Ruby there are essentially two ways, with a string to the REST end-point of a bucket, or with a hash, or combined way, where you can use string URI and override its parts with options. Also it is possible to specify set of nodes as array.

# using string URI
c = Couchbase.connect("")

# using Hash of options
c = Couchbase.connect(:hostname = ip, :port => port, bucket => bucket, :username => username, :password => password)

Couchbase.connect is just class method to create new instance of Couchbase::Bucket class, so you can substitute Couchbase.connect with


$cb = new Couchbase(ip:port, username, password, bucketname);


SDK get multi-get get-and-touch
Python bucket.get(key) or
- bucket.gat(key, expiry)
Python vmx cb.get(key) or
cb.get(array-of-keys) cb.get(key, ttl=ttl)
Ruby c.get(key) or
c.get(key1, key2, key3, ...) c.get(key, :ttl=ttl)
PHP $cb->get(key) $cb->getMulti(array-of-keys) cb->getAndTouch(key, expiry)


SDK set value set value with expiration multi-set
Python bucket.set(key, expiration, flags, value) or
bucket[key] = value
bucket.set(key, expiration, flags, value) or
bucket[key] = {'value': value, 'expiration': expiration}
Python vmx cb.set(key, value) or
cb[key] = value
cb.set(key, value, ttl=ttl) cb.set({key1: value1, key2: value2, ...})
Ruby c.set(key, value) or
c[key] = value
c.set(key, value, :ttl=ttl) c.set(key1 => value1, key2 => value2, ...)
PHP $cb->set(key, value) $cb->set(key, value, expiry) $cb->setMulti(array-of-key-value-pairs)
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.