couchbase安装python SDK

python 数据库 couchbase 阅读:848

Installing on Linux

  1. Debian and Ubuntu

# Only needed during first-time setup:
wget http://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-2-amd64.deb
sudo dpkg -i couchbase-release-1.0-2-amd64.deb
sudo apt-get update
sudo apt-get install libcouchbase-dev build-essential python-dev python-pip
sudo pip install couchbase

2.RHEL and CentOS

# Only needed during first-time setup:
wget http://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-2-x86_64.rpm
sudo rpm -iv couchbase-release-1.0-2-x86_64.rpm
# Will install or upgrade existing packages
sudo yum install libcouchbase-devel gcc gcc-c++ python-devel python-pip
sudo pip install couchbase

Installation on Mac OS X

brew update # get list of latest packages
brew install libcouchbase
brew install python
pip install couchbase

Installing on Microsoft Windows

Download the executable installer relevant to your platform and Python version fromhttps://pypi.python.org/pypi/couchbase#downloads

Note that installation by means of pip will not work on Windows.


Hello Couchbase

>>> from couchbase.bucket import Bucket
>>> cb = Bucket('couchbase://localhost/default')
>>> cb.upsert('u:king_arthur', {'name': 'Arthur',
...           'email': 'kingarthur@couchbase.com',
...           'interests': ['Holy Grail', 'African Swallows']})
OperationResult<RC=0x0, Key=u'u:king_arthur', CAS=0xb1da029b0000>
>>> cb.get('u:king_arthur').value
{u'interests': [u'Holy Grail', u'African Swallows'], u'name': u'Arthur', u'email': u'kingarthur@couchbase.com'}
>>> cb.n1ql_query('CREATE PRIMARY INDEX ON default').execute()
>>> from couchbase.n1ql import N1QLQuery
>>> row_iter = cb.n1ql_query(N1QLQuery('SELECT name FROM default WHERE ' +\
... '$1 IN interests', 'African Swallows'))
>>> for row in row_iter: print row
...
{u'name': u'Arthur'}


Connecting

from couchbase.bucket import Bucket
bucket = Bucket('couchbase://hostname-or-ip/bucket-name')