Couchbase Essentials (2015)
Appendix A. Couchbase SDKs
Throughout this book, we explored Couchbase SDKs. This appendix provides more details on obtaining and configuring the most popular Couchbase client libraries. The goal of this section is not to provide comprehensive documentation for each SDK, but rather to aid in your efforts to follow along with the examples in this book.
There are two types of Couchbase client libraries. The first type is the native libraries. These SDKs are written entirely in the language within which they will be used. In this category are the C#, Java, and C libraries. The second type of SDKs are wrappers around the Couchbase C client. These SDKs include Python, Ruby, PHP, and Node.js.
The Couchbase Developer Solutions team maintains the SDKs we just listed. There are other community-maintained clients. However, for the remainder of this appendix, we'll focus only on the official SDKs.
Couchbase Java SDK
The Couchbase Java SDK is a purely Java-based library. It is a highly performant package with support for both synchronous and asynchronous operations. The most recent version contains support for Java 8 and earlier releases.
Current version
This SDK should be used for development against Couchbase Server versions ranging from 2.5 to 3.x. Version 1.2 of the SDK was developed to support the earlier versions of Couchbase Server.
How to obtain it
Java developers will most likely want to use Maven to add the Java SDK to their projects. The package is accessible from Maven Central:
<dependencies>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
Additionally, the SDK team publishes the Java binaries, which may be found at http://docs.couchbase.com/developer/java-2.0/download-links.html. The source code for the library is available on GitHub at https://github.com/couchbase/couchbase-java-client.
The basics
The following snippet demonstrates the basics of using the Couchbase Java SDK:
//Configure the cluster
CouchbaseCluster cluster = CouchbaseCluster.create("127.0.0.1");
//Open a bucket connection
Bucket bucket = cluster.openBucket("default");
//Create, and store a JSON document
JsonObject message = JsonObject.create().put("message", "The Hello, World!");
JsonDocument document = bucket.insert(JsonDocument.create("somekey", message));
//Read the document
JsonDocument savedMessage = bucket.get("somekey");
// Close the bucket connection
cluster.disconnect();
Couchbase .NET SDK
The Couchbase .NET SDK is a purely C#-based library. Currently, the latest version is 2.0. This version contains support for .NET 4.5+.
Current version
This SDK should be used for all development purposes against all Couchbase Server versions from 2.5 to 3.x. Version 1.3 of the SDK was developed to support earlier versions of Couchbase Server.
How to obtain it
The .NET developers will most likely want to use NuGet to add the Couchbase .NET SDK to their Visual Studio projects. To install Couchbase SDK 2.0, run the following command in Package Manager Console:
PM> Install-Package CouchbaseNetClient
Additionally, the SDK team publishes the .NET binaries, which can be found at http://docs.couchbase.com/developer/dotnet-2.0/download-links.html. The source code for the library is available on GitHub at https://github.com/couchbase/couchbase-net-client.
The basics
The following snippet demonstrates the basics of using the Couchbase .NET SDK:
//Configure the cluster defaulting to "127.0.0.1"
var cluster = new Cluster();
//Open a bucket connection defaulting to "default"
var bucket = cluster.OpenBucket();
//Create, and store a JSON document
var document = new Document<dynamic> {
Id = "somekey", {
Content = new { Message = "Hello, World!" };
bucket.Upsert(document);
//Read the document
var savedMessage = bucket.GetDocument<dynamic>("somekey");
// Close the bucket connection
bucket.Dispose();
Couchbase PHP SDK
The Couchbase PHP SDK is a PHP library that wraps the Couchbase C SDK. Before installing this library, the C library must be installed.
Current version
Currently, the latest version is 2.0.2. This SDK should be used for all development against Couchbase Server versions from 2.5 to 3.x.
How to obtain it
Linux users will be able to install the PHP SDK with pecl as follows:
$ pecl install couchbase
Additionally, the SDK team publishes Windows binaries, which may be found at http://docs.couchbase.com/developer/php-2.0/download-links.html. The source code for the library is available on GitHub at https://github.com/couchbase/php-ext-couchbase.
The basics
Here are a few snippets that demonstrate the basics of using the Couchbase PHP SDK:
//Configure the cluster
$cluster = new CouchbaseCluster('http://127.0.0.1:8091');
//Open a bucket connection
$bucket = $cluster->openBucket('default');
// Close the bucket connection
cluster.disconnect();
The Couchbase Node.js SDK
The Couchbase Node.js SDK is a Node.js library that wraps the Couchbase C SDK. Before installing this library, the C library must be installed.
Current version
Currently, the latest version is 2.0.2. This SDK should be used for all development against Couchbase Server versions from 2.5 to 3.x.
How to obtain it
The Node.js users will likely wish to use the npm package manager to install the Couchbase Node.js SDK. Windows users must also have node-gyp along with Visual C++ 10. Information on installing node-gyp is available at https://github.com/TooTallNate/node-gyp.
$ npm install couchbase
Additionally, the SDK team publishes binaries, which may be found at http://docs.couchbase.com/developer/node-2.0/download-links.html. The source code for the library is available on GitHub at https://github.com/couchbase/couchnode.
The basics
The following snippet demonstrates the basics of using the Couchbase PHP SDK:
var couchbase = require('couchbase');
var cluster = new couchbase.Cluster();
var bucket = cluster.openBucket('default');
Couchbase Python SDK
The Couchbase Python SDK is a Python library wrapping the Couchbase C SDK. Before installing this library, the C library must be installed.
Current version
Currently, the latest version is 1.2. This SDK should be used for all development against Couchbase Server versions from 2.5 to 3.x.
How to obtain it
Python users can obtain the Couchbase Python SDK through the pip package manager as follows:
$ pip install couchbase
The SDK team publishes binaries, which may be found at https://pypi.python.org/pypi/couchbase#downloads. The source code for the library is available on GitHub at https://github.com/couchbase/couchbase-python-client.
The basics
The following snippet demonstrates the basics of using the Couchbase PHP SDK:
client = Couchbase.connect(bucket='default', host='localhost')
Couchbase Ruby SDK
The Couchbase Ruby SDK is a Python library wrapping the Couchbase C SDK. Before installing this library, the C library must be installed.
Current version
Currently, the latest version is 1.3. This SDK should be used for all development against Couchbase Server versions from 2.5 to 3.x.
How to obtain it
Ruby users can find the Couchbase Ruby SDK through the gem package manager as follows:
$ gem install couchbase
The basics
The following snippet demonstrates the basics of using the Couchbase PHP SDK:
client = Couchbase.connect(:bucket=>'default', :host=>'localhost')
Couchbase C SDK
The Couchbase C client library is the core library for several other libraries. It is an asynchronous, single-threaded SDK using callbacks for all operations. It is available on Windows, Linux, and Mac OS X.
Current version
Currently, the latest version is 2.4.5. This SDK should be used for all development against Couchbase Server versions from 2.5 to 3.x.
How to obtain it
C developers can find instructions on building or obtaining the library at http://docs.couchbase.com/developer/c-2.4/download-install.html. Numerous binaries are available at this location.