Skip to main content

About

Couchdbkit provides you a full featured and easy client to access and manage CouchDB. It allows you to manage a CouchDB server, databases, doc managements and view access. All objects mostly reflect python objects for convenience. Server and Databases objects could be used for example as easy as using a dict.

Installation

Couchdbkit requires Python 2.x superior to 2.5.

Install from sources:

$ python setup.py install

Or from Pypi:

$ easy_install -U couchdbkit

Getting started

This tutorial exposes key features of this library mainly through code examples. For in-depth description of the modules, you’ll want to read the API documentation.

Write your first CouchDB document

import datetime
from couchdbkit import *

class Greeting(Document):
    author = StringProperty()
    content = StringProperty()
    date = DateTimeProperty()

Store the submitted Greetings

Here is the code to save a greet on Greeting database. We also see how to create a database:

# server object
server = Server()

# create database
db = server.get_or_create_db("greeting")

# associate Greeting to the db
Greeting.set_db(db)

# create a new greet
greet = Greeting(
    author="Benoit",
    content="Welcome to couchdbkit world",
    date=datetime.datetime.utcnow()
)

# save it
greet.save()

Note: Here we use contain to associate the db to the Greeting object. This function could be use to associate multiple dcouemnt objects to one db:

contain(db, Doc1, ...)

Your document greet is now in the greetings db. Each document is saved with a doc_type field that allow you to find easily each kind of document with the views. By default doc_type is the name of the class.

Now that you saved your document, you can update it:

greet.author = u"Benoît Chesneau"
greet.save()

Here we updated the author name.

Dynamic properties

Mmm ok, but isn’t CouchDB storing documents schema less? Do you want to add a property ? Easy:

greet.homepage = “http://www.e-engura.org” greet.save()

Now you have just added an homepage property to the document.

Get all greetings

You first have to create a view and save it in the db. We will call it greeting/all. To do this we will use the loader system of couchdbkit that allows you to send views to CouchDB.

Let’s create a folder that contains the design doc, and then the folder for the view. On unix :

mkdir -p ~/Work/couchdbkit/example/_design/greeting/views/all

In this folder we edit a file map.js:

function(doc) {
  if (doc.doc_type == "Greeting")
    emit(doc._id, doc);
}

On Textmate, you have:

couchdbkit textmate screen

A system will be provided to manage view creation and other things. As some noticed, this system works like couchapp.

Then we use FileSystemDocsLoader object to send the design document to CouchDB:

from couchdbkit.loaders import FileSystemDocsLoader

loader = FileSystemDocsLoader('/path/to/example/_design')
loader.sync(db, verbose=True)

The design doc is now in the greetings database and you can get all greets:

greets = Greeting.view('greeting/all')

Release files for couchdbkit 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for couchdbkit 0.4.3
File Size Uploaded
couchdbkit-0.4.3.tar.gz 83.3 kB Details

Release files / couchdbkit-0.4.3.tar.gz

Download URL couchdbkit-0.4.3.tar.gz
Size 83.3 kB
Tags Source
SHA-256 checksum
How to use checksums
244ab5f969d3b1afd1713312fb1a7f6bddd01326b3316c6c5862f3ad370717cc
BLAKE2b-256 checksum
How to use checksums
d446cd6e1fc4de2b1ed140c62fc2308e7926f1357acbcb14a930f90891c8c3bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.7

1 release file

0.5.6

1 release file

0.5.4

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.11

1 release file

0.4.10

1 release file

0.4.9

1 release file

0.4.8

1 release file

0.4.7

1 release file

0.4.6

1 release file

0.4.5

1 release file

0.4.4

1 release file

This release

0.4.3 This release

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7.2

1 release file

0.1.7.1

1 release file

0.1.7

1 release file

0.1.6.1

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page