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.

Python

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.

Ruby

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("http://example.com:8091/pools")

# 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 Couchbase::Bucket.new.

PHP

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

Perl

my $cb = Couchbase::Client->new({server => "server", username => "user", password => "password"});

Get

SDK get multi-get get-and-touch
Python bucket.get(key) or
bucket[key]
- bucket.gat(key, expiry)
Python vmx cb.get(key) or
cb[key]
cb.get(array-of-keys) cb.get(key, ttl=ttl)
Ruby c.get(key) or
c[key]
c.get(key1, key2, key3, ...) c.get(key, :ttl=ttl)
PHP $cb->get(key) $cb->getMulti(array-of-keys) cb->getAndTouch(key, expiry)
Perl $cb->get(key) $cb->get_multi(array-of-keys) cb->get(key, 
Unknown macro: { exp => expiry }

)

Set

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)
Perl $cb->set(key, value) $cb->set(key, value, 
Unknown macro: { exp => $expiry }

)

$cb->set_multi([key, value,
Unknown macro: { exp => expiry}

], ...)

https://github.com/mnunberg/perl-Couchbase-Client/commit/b4ee1413746fe58f99d53e48a4560aa794ec195c

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.