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

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.1.tar.gz (258.7 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.1.win-amd64-py3.3.exe (500.2 kB view details)

Uploaded Source

couchbase-1.2.1.win-amd64-py3.2.exe (503.4 kB view details)

Uploaded Source

couchbase-1.2.1.win-amd64-py2.7.exe (503.1 kB view details)

Uploaded Source

couchbase-1.2.1.win-amd64-py2.6.exe (503.3 kB view details)

Uploaded Source

couchbase-1.2.1.win32-py3.3.exe (444.0 kB view details)

Uploaded Source

couchbase-1.2.1.win32-py3.2.exe (450.1 kB view details)

Uploaded Source

couchbase-1.2.1.win32-py2.7.exe (450.3 kB view details)

Uploaded Source

couchbase-1.2.1.win32-py2.6.exe (450.5 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for couchbase-1.2.1.tar.gz
Algorithm Hash digest
SHA256 f7a309cc6a713a8972dd0b46b0137752edf968b6f47f15ed591072f05cc77849
MD5 1d7d4f38a0d32f88a5d915c07cf83491
BLAKE2b-256 4872b3cbe9b1705c35a52d361e16ef3fbc374fb36e4eebd84a90a63ae1f3b64b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 5cff5c477721f5c727289ede2e3058fe50ca5f93b7bbf891b445bcfee1466744
MD5 50bd77e81930339fa4df4638c25d572a
BLAKE2b-256 a459a0bea06f1eea9753e6e00a90d5a40b2c770185826edfab46104ea3897586

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win-amd64-py3.2.exe
Algorithm Hash digest
SHA256 3d8a4b2a64e8719aee26e5dccc4f6d0f52cdc9b0f0d1d82edfe467bc5ce6f324
MD5 7d611d1052652ce769595b0e20020bac
BLAKE2b-256 efef1547d15412c9e5d2b3044ebe84c64f89e22643fa40aad6aa149e91220c1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 f0d466fde44ff3e7e9074f55c49b714874847f89f7197799b92071400ad3c1af
MD5 4f8bfafc0230b84fb76d273011174609
BLAKE2b-256 c14eae62c24d19df2d6335fdcf4eeb1824e8a705a2e67767cd8d4872ddaa53db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 e17ea10628b83ba3cfdaa3cf2824cec08beae8895c4c6b69af020a64d0740baf
MD5 870c5dbe82a8f61d24dba8c0c314acfe
BLAKE2b-256 5f381315ae769d39f40bcc876b2879d461d85e1e24b8bdaf57459afefbd72c28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win32-py3.3.exe
Algorithm Hash digest
SHA256 fd4d27001360e47720f4015a894bc56dd2d163cfea4b74c811dbc8a0221b3322
MD5 33bb1e50d25db73410c0855be716e192
BLAKE2b-256 7aca3d003d798c16c3755770949bdb7565275e0ef660ca4f04ab2be0603e3660

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win32-py3.2.exe
Algorithm Hash digest
SHA256 f7bd20bf9c948f18c5b46f3d460f955c3027fc46d59dd76b3986ecceac0fab37
MD5 78bbcb18ae2fab2f711cc39aa7d34546
BLAKE2b-256 6ebc6b27cb868c618077ef9628b8ed4b16e88c912b28dfd152e855d170369197

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win32-py2.7.exe
Algorithm Hash digest
SHA256 15590c48cde373f667a474df525a5a6fe7c031dd5796065b6370089ebd8fa9e0
MD5 5da69f159ab6d5c89307d47f111a5af6
BLAKE2b-256 bb6d2bd380d95b4b288e82239fee1dae5373e08f2b3d730bbdd5a4abe46efc21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for couchbase-1.2.1.win32-py2.6.exe
Algorithm Hash digest
SHA256 ad028760a729a48cd11527a8e2b9e983ec233d2e89b2bda73674957da1958a33
MD5 1c8940efa72bae17eccd9e027fdff4d3
BLAKE2b-256 ac9bb8663fba2eddfab7be9d9b08ef80a80dfe6fdb0d9e67081e3d7989ae4ae7

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