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.

If you have a recent version of pip, you may use the latest development version by issuing the following incantation

pip install git+git://github.com/couchbase/couchbase-python-client

Prerequisites

Building

The following will compile the module locally; you can then test basic functionality including running the examples.

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.

Installing

python setup.py install

Using

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

>>> from couchbase.bucket import Bucket
>>> c = Bucket('couchbase://localhost/default')
>>> c
<couchbase.bucket.Bucket bucket=default, nodes=['localhost:8091'] at 0x105991cd0>
>>> c.upsert("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.bucket import Bucket
>>> c = Bucket('couchbase://localhost/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.bucket

from twisted.internet import reactor
from txcouchbase.bucket import Bucket

cb = Bucket('couchbase://localhost/default')
def on_upsert(ret):
    print "Set key. Result", ret

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

cb.upsert("key", "value").addCallback(on_upsert)
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

from gcouchbase.bucket import Bucket

conn = Bucket('couchbase://localhost/default')
print conn.upsert("foo", "bar")
print conn.get("foo")

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

PyPy

PyPy is an alternative high performance Python implementation. Since PyPy does not work well with C extension modules, this module will not work directly. You may refer to the alternate implementation based on the cffi module: https://github.com/couchbaselabs/couchbase-python-cffi

Other Examples

There are other examples in the examples directory. To run them from the source tree, do something like

PYTHONPATH=$PWD ./examples/bench.py -U couchbase://localhost/default

Building documentation

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

2.0.6

Download files

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

Source Distribution

couchbase-2.0.6.tar.gz (196.2 kB view details)

Uploaded Source

Built Distributions

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

couchbase-2.0.6.win-amd64-py3.4.exe (601.3 kB view details)

Uploaded Source

couchbase-2.0.6.win-amd64-py3.3.exe (601.4 kB view details)

Uploaded Source

couchbase-2.0.6.win-amd64-py3.2.exe (601.8 kB view details)

Uploaded Source

couchbase-2.0.6.win-amd64-py2.7.exe (601.5 kB view details)

Uploaded Source

couchbase-2.0.6.win32-py3.4.exe (537.4 kB view details)

Uploaded Source

couchbase-2.0.6.win32-py3.3.exe (537.6 kB view details)

Uploaded Source

couchbase-2.0.6.win32-py3.2.exe (542.1 kB view details)

Uploaded Source

couchbase-2.0.6.win32-py2.7.exe (542.3 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for couchbase-2.0.6.tar.gz
Algorithm Hash digest
SHA256 2eecfade90400b7c9886b21e88ab40ceaf9efbb0123ddef4addb58befc33a451
MD5 5c8215f0b997f4a65bde148f54a79c0e
BLAKE2b-256 ab4463cdd3b644fca84d801c6c5915e482584f928017c9914cf24a221b7a9833

See more details on using hashes here.

File details

Details for the file couchbase-2.0.6.win-amd64-py3.4.exe.

File metadata

File hashes

Hashes for couchbase-2.0.6.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 43545c1ea1dc04372a5d10a7b559a242321b8550e1a63297964afb6f23eeb0a7
MD5 ba24c02650cbc2e435586f2ffe66b74e
BLAKE2b-256 d1099bf19e0f29ed2f838c960a527a1d17fde68b3c1c99e32e96d505ac0f0fba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-2.0.6.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 3f5d8854db9c75bda5d8ed522fde05d4b447fef2d90d5ead7d8adf64f4d6017f
MD5 b3cf700722b54180cc47ce3745146b92
BLAKE2b-256 363134ce940b373e66947b6410abf733e3c10d70170490cfa650c2761199fa70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-2.0.6.win-amd64-py3.2.exe
Algorithm Hash digest
SHA256 e0a922ece0ee04e76c99c8b76fb72cf9725204a3f7b45af64814c9146e80aa13
MD5 7b64eebe3c213af6ed7f6272192f98a7
BLAKE2b-256 3d75d8f74c2186e001da61aa3e48562ea04817ac722750daff96e5c15251df83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-2.0.6.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 bcffd37b37a73b35c531aee2941e926257f3458034ff7f943381534964f56360
MD5 31cc5f0b95e412637519c72b97352903
BLAKE2b-256 010f9d710d3ec402deafa53abd4f1a34cb74436eab6fc39d362c41b8d9a23c18

See more details on using hashes here.

File details

Details for the file couchbase-2.0.6.win32-py3.4.exe.

File metadata

File hashes

Hashes for couchbase-2.0.6.win32-py3.4.exe
Algorithm Hash digest
SHA256 bdd96ed62170cef099d0aa8526ddf69d7cf593c48f2f0d3c89463d6414268e51
MD5 84d2c3c705de726830f3cec2d81912d4
BLAKE2b-256 2992c58469a581f5d43d2c98b7075cbf26c4ba07307a3a5f16f7f20d90edb5c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-2.0.6.win32-py3.3.exe
Algorithm Hash digest
SHA256 38ea471240b4b8a05c131a3572182ded90c55b22cf853282de71689b2f18c6cb
MD5 9705e542ecfd27f60d852f7a5c513f20
BLAKE2b-256 cf9172e527e190ea63e8269759216ad91334f87500417c5979d06a428c74ce26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-2.0.6.win32-py3.2.exe
Algorithm Hash digest
SHA256 72b498026fd948cd0e77f174b707b006767ba508e59ac4061222d28f3eefb6b7
MD5 53d238f52b44cd7f5c1f83e5859242ab
BLAKE2b-256 a988a46bace1b77e777671cfa45557274a71305c4f718196d322913716c7974e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-2.0.6.win32-py2.7.exe
Algorithm Hash digest
SHA256 001d59bc1318d0b51cc566f4b84ce2a0e3b4efaaaf986ed3f3792ad264ccee7e
MD5 8b8473235bdac85839035dc73333842d
BLAKE2b-256 adc620a681adda15bbb4aa22ffb1345e6e0a7bcaeba00fd364607c20d312f45d

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