View Source

h1. 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|https://groups.google.com/group/couchbase].


h2. 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.

h3. Python


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

h3. Python vmx

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

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

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.

h3. 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.

{code}
# 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)
{code}

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

h3. PHP


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

h3. Perl

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

h2. 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, \{ exp => expiry \}) |

h2. 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, \{ exp => $expiry \}) | $cb->set_multi(\[key, value, \{ exp => expiry \}\], ...) |
[https://github.com/mnunberg/perl-Couchbase-Client/commit/b4ee1413746fe58f99d53e48a4560aa794ec195c]