GithubHelp home page GithubHelp logo

bigbluehat / couchbase-python-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from couchbase/couchbase-python-client

1.0 2.0 0.0 528 KB

Couchbase .Python client library (official)

Home Page: http://www.couchbase.org

License: Apache License 2.0

Python 100.00%

couchbase-python-client's Introduction

========================
COUCHBASE PYTHON LIBRARY
========================

This library provides methods to connect to both the couchbase
memcached interface and the couchbase rest api interface.

Two simple use cases to set and get a key in the default bucket
and then create a new bucket using the memcached and rest clients::

    #!/usr/bin/env python

    from couchbase.couchbaseclient import CouchbaseClient
    from couchbase.couchbaseclient import MemcachedTimeoutException
    from couchbase.rest_client import RestConnection

    client = CouchbaseClient("http://localhost:8091/pools/default",
                             "default","",False)
    client.set("key1", 0, 0, "value1")
    client.get("key1")

    server_info = {"ip":"localhost",
                   "port":8091,
                   "username":"Administrator",
                   "password":"password"}
    rest = RestConnection(server_info)
    rest.create_bucket(bucket='newbucket',
                       ramQuotaMB=100,
                       authType='none',
                       saslPassword='',
                       replicaNumber=1,
                       proxyPort=11215,
                       bucketType='membase')

Example code that creates buckets and then does sets, gets and views using
the unified client::

    import couchbase

    # connect to a couchbase server
    cb = couchbase.Server('localhost:8091',
                          username='Administrator',
                          password='password')

    # create default bucket if it doesn't exist
    try:
        cb.create('default')
    except:
        pass

    # fetch a Bucket with subscript
    default_bucket = cb['default']
    # set a value with subscript (equivilent to .set)
    default_bucket['key1'] = 'value1'

    # fetch a bucket with a function
    default_bucket2 = cb.bucket('default')
    # set a json value with subscript (equivilent to .set)
    default_bucket2['key2'] = {'value':'value2','expiration':0,'flags':10}

    # set a value with a function
    default_bucket.set('key3', 0, 0, 'value3')

    # fetch a key with a function
    print 'key1 ' + str(default_bucket.get('key1'))
    print 'key2 ' + str(default_bucket2.get('key2'))
    # fetch a key with subscript
    print 'key3 ' + str(default_bucket2['key3'])

    # delete a bucket
    cb.delete('default')
    try:
        cb['default']
    except Exception as ex:
        print ex

    # create a new bucket
    try:
        newbucket = cb.create('newbucket', ram_quota_mb=100, replica=1)
    except:
        newbucket = cb['newbucket']

    # set a json document with a function
    # this will translate $flags and $expiration to memcached protocol
    # automatically generate the _id
    doc_id = newbucket.save({'type':'item',
                             'value':'json test',
                             '$flags':25})
    print doc_id + ' ' + str(newbucket[doc_id])
    # use a provided _id
    doc_id = newbucket.save({'_id':'key4',
                             'type':'item',
                             'value':'json test',
                             '$flags':25})
    print doc_id + ' ' + str(newbucket[doc_id])

    design = {
        "_id" : "_design/testing",
        "language" : "javascript",
        "views" : {
            "all" : {
                "map" : '''function (doc) {\n    emit(doc, null);\n}'''
                },
            },
        }
    # save a design document
    # right now with no _rev, we can only create, we can't update
    try:
        doc_id = newbucket.save(design)
    except:
        doc_id = "_design/testing"

    rows = newbucket.view("_design/testing/_view/all")
    for row in rows:
        print row


This version requires Python 2.6 or later

Open Issues : http://www.couchbase.org/issues/browse/PYCBC

=============
RUNNING TESTS
=============

Requirements:
* easy_install nose
* pip install nose-testconfig

We're now using nose to run our tests. There's a supplied
test.ini.template that you can customize to match your installed
environment. Copy test.ini.template to test.ini, customize, and
then run the following command:

    nosetests --tc-file=test.ini

Adding coverage information is as easy as install coverage and running
nosetests with these settings:

    nosetests --tc-file=test.ini --with-coverage
--cover-package=couchbase --cover-html

This will output coverage reports into the 'cover' directory.

couchbase-python-client's People

Contributors

farshidce avatar kbatten avatar bigbluehat avatar bcui6611 avatar jzablocki avatar ingenthr avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.