Skip to main content

Python Client for Couchbase

Project description

Client for Couchbase.

https://travis-ci.org/couchbase/couchbase-python-client.png

Building and Installing

This only applies to building from source. If you are using a Windows installer then everything (other than the server) is already included. See below for windows snapshot releases.

Also note that these instructions apply to building from source. You can always get the latest supported release version from PyPi

Prerequisites

Building

python setup.py build_ext --inplace

If your libcouchbase install is in an alternate location (for example, /opt/local/libcouchbase), you may add extra directives, like so

python setup.py build_ext --inplace \
    --library-dir /opt/local/libcouchbase/lib \
    --include-dir /opt/local/libcouchbase/include

Or you can modify the environment CFLAGS and LDFLAGS variables.

Windows Snapshots

A list of recent snapshot builds for Windows may be found here <http://packages.couchbase.com/clients/python/snapshots>.

You can always get release binaries from PyPi (as above).

Using

Here’s an example code snippet which sets a key and then reads it

>>> from couchbase import Couchbase
>>> c = Couchbase.connect(bucket='default')
>>> c
<couchbase.connection.Connection bucket=default, nodes=['127.0.0.1:8091'] at 0xb21a50>
>>> c.set("key", "value")
OperationResult<RC=0x0, Key=key, CAS=0x31c0e3f3fc4b0000>
>>> res = c.get("key")
>>> res
ValueResult<RC=0x0, Key=key, Value=u'value', CAS=0x31c0e3f3fc4b0000, Flags=0x0>
>>> res.value
u'value'
>>>

You can also use views

>>> from couchbase import Couchbase
>>> c = Couchbase.connect(bucket='beer-sample')
>>> resultset = c.query("beer", "brewery_beers", limit=5)
>>> resultset
View<Design=beer, View=brewery_beers, Query=Query:'limit=5', Rows Fetched=0>
>>> for row in resultset: print row.key
...
[u'21st_amendment_brewery_cafe']
[u'21st_amendment_brewery_cafe', u'21st_amendment_brewery_cafe-21a_ipa']
[u'21st_amendment_brewery_cafe', u'21st_amendment_brewery_cafe-563_stout']
[u'21st_amendment_brewery_cafe', u'21st_amendment_brewery_cafe-amendment_pale_ale']
[u'21st_amendment_brewery_cafe', u'21st_amendment_brewery_cafe-bitter_american']

Twisted API

The Python client now has support for the Twisted async network framework. To use with Twisted, simply import txcouchbase.connection instead of couchbase.Couchbase

from twisted.internet import reactor
from txcouchbase.connection import Connection as TxCouchbase

cb = TxCouchbase(bucket='default')
def on_set(ret):
    print "Set key. Result", ret

def on_get(ret):
    print "Got key. Result", ret
    reactor.stop()

cb.set("key", "value").addCallback(on_set)
cb.get("key").addCallback(on_get)
reactor.run()

# Output:
# Set key. Result OperationResult<RC=0x0, Key=key, CAS=0x9a78cf56c08c0500>
# Got key. Result ValueResult<RC=0x0, Key=key, Value=u'value', CAS=0x9a78cf56c08c0500, Flags=0x0>

The txcouchbase API is identical to the couchbase API, except that where the synchronous API will block until it receives a result, the async API will return a Deferred which will be called later with the result or an appropriate error.

GEvent API

The experimental_gevent_support constructor flag has now been removed. Instead, you can import the gcouchbase.connection package and use the GConnection class like so:

from gcouchbase.connection import GCouchbase
conn = GCouchbase(bucket='default')
print conn.set("foo", "bar")
print conn.get("foo")

The API functions exactly like the normal Connection API, except that the implementation is significantly different.

Note that the new GCouchbase class does not use the same implementation as the experimental support featured in 1.1.0

Other Examples

There are other examples in the examples directory.

Building documentaion

The documentation is using Sphinx and also needs the numpydoc Sphinx extension. To build the documentation, go into the docs directory and run

make html

The HTML output can be found in docs/build/html/.

Testing

For running the tests, you need the standard unittest module, shipped with Python. Additionally, the testresources package is required.

To run them, use either py.test, unittest or trial.

The tests need a running Couchbase instance. For this, a tests.ini file must be present, containing various connection parameters. An example of this file may be found in tests.ini.sample. You may copy this file to tests.ini and modify the values as needed.

The simplest way to run the tests is to declare a bucket_prefix in the tests.ini file and run the setup_tests.py script to create them for you.

python setup_tests.py

To run the tests:

nosetests

Support

If you found an issue, please file it in our JIRA. You may also ask in the #libcouchbase IRC channel at freenode. (which is where the author(s) of this module may be found).

License

The Couchbase Python SDK is licensed under the Apache License 2.0.

Project details


Release history Release notifications | RSS feed

This version

1.2.4

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

couchbase-1.2.4.tar.gz (257.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

couchbase-1.2.4.win-amd64-py3.3.exe (520.2 kB view details)

Uploaded Source

couchbase-1.2.4.win-amd64-py3.2.exe (522.9 kB view details)

Uploaded Source

couchbase-1.2.4.win-amd64-py2.7.exe (522.6 kB view details)

Uploaded Source

couchbase-1.2.4.win-amd64-py2.6.exe (522.9 kB view details)

Uploaded Source

couchbase-1.2.4.win32-py3.3.exe (465.2 kB view details)

Uploaded Source

couchbase-1.2.4.win32-py3.2.exe (471.3 kB view details)

Uploaded Source

couchbase-1.2.4.win32-py2.7.exe (471.5 kB view details)

Uploaded Source

couchbase-1.2.4.win32-py2.6.exe (471.7 kB view details)

Uploaded Source

File details

Details for the file couchbase-1.2.4.tar.gz.

File metadata

  • Download URL: couchbase-1.2.4.tar.gz
  • Upload date:
  • Size: 257.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for couchbase-1.2.4.tar.gz
Algorithm Hash digest
SHA256 4ebd038d2f8cc19e5d02da5dc8e470664d87ec2c569d8f7133da68f3fe8218cb
MD5 4a51bf3ac1fa26bcb9433d53ac4ba34b
BLAKE2b-256 476cd6c008c9d0a7ccd1628480e22e337c29adec444912cfed63aa71f319dca7

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 660fd7a7d7898addd0e695f37639ca38b5994132ba802890a6fc3368735c42e3
MD5 f2b1b8d335c0f2560fe0175c885380d9
BLAKE2b-256 88e27617bd393a28274592e0f9190b4eb160b10ce094524d659754aeaf6c4a36

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win-amd64-py3.2.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win-amd64-py3.2.exe
Algorithm Hash digest
SHA256 41ea6ed554e2cc8bb9fa06d62577ccaefb6453eb9b4932420610dddd56f16b8c
MD5 9df0b4b45d1bf7e1c4b663fedc9efb0a
BLAKE2b-256 1765379369e5c31a06b0b81719123836bc76978ea8fb7715481d31f98e19bc22

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 5583259808442765111c16f4102aac25705eb60e5ce6d3f48c780457c00cfe5e
MD5 6fdc81570d2c5bc1f96201ff8b1703d3
BLAKE2b-256 251fad8ca7e8fe6b9d9572506557c286b12f6a4d2c760402274e4524da619e2c

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win-amd64-py2.6.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 845f9afbd179652db2c5a184bbc487275a6e8cb89100e54b88ba1f313561187c
MD5 467b4407239d7b515a7459bb457ea98e
BLAKE2b-256 7c30492e37eef99fcd5b9ff8e495506687123c60a84c3987f676dc86d93154a4

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win32-py3.3.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win32-py3.3.exe
Algorithm Hash digest
SHA256 911d8fd6fd6843ef536f87a911304e4f0df14f628bf6e5d728b00ea640e0809b
MD5 41d826954ec0100e80520b0f077763eb
BLAKE2b-256 8db55c693f659183e4b844816ebce29b7f78f290f80471c5a42d7772503b9782

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win32-py3.2.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win32-py3.2.exe
Algorithm Hash digest
SHA256 c1cc980affb7c96a8418d19f8df1b524f5556552d454d9de8fccef5b4a924100
MD5 d76e0a889dcd256f97ed017309f144ef
BLAKE2b-256 9a68f2bbf85bd04c146aeb247e1fdd62b16d12610ea0994ee1bb037cd4ea0e5a

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win32-py2.7.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win32-py2.7.exe
Algorithm Hash digest
SHA256 d6e6594ea0d09ee935f66598ad6cd25a297d4b4c69a9b0de6e9a6146c68e2afc
MD5 3d70faf451d901f5b477a96772862181
BLAKE2b-256 4ed4929294c32c80a70acf917dedc8e0ff3d12640a3072fbbe3e51889ae5e65a

See more details on using hashes here.

File details

Details for the file couchbase-1.2.4.win32-py2.6.exe.

File metadata

File hashes

Hashes for couchbase-1.2.4.win32-py2.6.exe
Algorithm Hash digest
SHA256 fe542f6491bfc8d15c879c4579c8aa7656a879322da58b288913a36f64611863
MD5 42af2ed4f37610034ecad59bca78beb2
BLAKE2b-256 e2d1b5bc0435a04a8ec6fa8ae1e1d3e3886fd4b84f11eaee70ef77d1c1864188

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page