Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Python library for simple and dynamic access to CouchDB

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 couchquery
Octocat-spinner-32 tests
Octocat-spinner-32 .coveragerc
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 README.md
Octocat-spinner-32 requirements.txt
Octocat-spinner-32 setup.py
README.md

Couchquery

Build Status Coverage Status

Python library for simple and dynamic access to CouchDB. This libary is authored by Mikeal Rogers and currently maintained by Nicholas Tan Jerome.

Further document on this library can be obtained hier

Getting Started

You will need CouchDB

After installing CouchDB, start it with

sudo couchdb -b

You can now launch http://127.0.0.1:5984/_utils/index.html

Shutdown using

sudo couchdb -d

Installation

pip install couchquery

How to use

Couchquery is meant to be a simple python libary for CouchDB

Create a Database object for any CouchDB database you would like to interact with.

>>> db = Database('http://localhost:5984/buckaroo')

Create a new document in the database.

>>> db.create({'type':'red-lectroid','name':'John Whorfin'})
{u'rev': u'1-4198154595', u'ok': True, u'id': u'c581bbc8fd32f49ecb2f8668ed71fe9b'}

After creating a new document you are given the response dict from couch which includes the id of the document. You can also get documents by id.

>>> info = db.create({'type':'red-lectroid','name':'John Whorfin'})
>>> doc = db.get(info['id'])
>>> type(doc)
<class 'couchquery.Document'>

Document objects are just slightly extended dict objects that provide slightly simpler attribute access.

>>> doc.name
"John Worfin"
>>> doc['name']
"John Worfin"
>>> doc.location = "The 8th Dimension"
>>> doc.has_key('location')
True
>>> doc.get('fakeattribute', False)
False

When saving documents you must have the latest revision.

>>> db.update(doc)

Please read on the document for further information.

Changes

0.10.1

  • Hotfix: should not raise exception when it returns Http response 304.

0.10.0

  • https support
  • supports credentials usage
  • support url encoding on document id
  • better error message for createdb and deletedb

Tests

If you clone this repository, it is a good practice to run the tests first to make sure that you have a working environment. You can do this by either:

py.test tests

or

nosetests
Something went wrong with that request. Please try again.