Skip to main content

Python couchdb kit

Project description

About the jsonobject fork of couchdbkit

jsonobject-couchdbkit is a fork of couchdbkit that replaces couchdbkit.schema with a thin wrapper around jsonobject (which was, incidentally, written as a way faster replacement for couchdbkit.schema.) See jsonobject.

About

Couchdbkit provides you a full featured and easy client to access and manage CouchDB. It allows you to manage a CouchDBserver, 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.

Build Status

Installation

Couchdbkit requires Python 2.x superior to 2.6.

To install couchdbkit using pip you must make sure you have a recent version of distribute installed:

$ curl -O http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py
$ easy_install pip

To install or upgrade to the latest released version of couchdbkit:

$ pip install 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

from couchdbkit import Server
# server object
server = Server()

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

doc = {"mydoc": "test"}
db.save_doc(doc)
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:

from couchdbkit import Server

# 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()

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"Benoit 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);
    }
}

Here is a folder structure:

/Work/couchdbkit/example/:

--_design/
---- greetings
------ view

Here is a screenshot:

http://couchdbkit.org/images/gettingstarted.png

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

Then we use push function to send the design document to CouchDB:

from couchdbkit.designer import push
push('/path/to/example/_design/greetings', db)

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonobject-couchdbkit-0.9.12.tar.gz (67.0 kB view details)

Uploaded Source

Built Distribution

jsonobject_couchdbkit-0.9.12-py2.py3-none-any.whl (59.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jsonobject-couchdbkit-0.9.12.tar.gz.

File metadata

  • Download URL: jsonobject-couchdbkit-0.9.12.tar.gz
  • Upload date:
  • Size: 67.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/3.6.3

File hashes

Hashes for jsonobject-couchdbkit-0.9.12.tar.gz
Algorithm Hash digest
SHA256 6c090c61c92a1daa7c4bedd907c43021dc0ae6476d4af1a3934885a46787544e
MD5 8c32a9da0b1eff3a683ff2ef396fb445
BLAKE2b-256 c779e293475cb43a664ba42d62f921f79d0523e1b06e3226f845edb1536aedef

See more details on using hashes here.

Provenance

File details

Details for the file jsonobject_couchdbkit-0.9.12-py2.py3-none-any.whl.

File metadata

  • Download URL: jsonobject_couchdbkit-0.9.12-py2.py3-none-any.whl
  • Upload date:
  • Size: 59.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/3.6.3

File hashes

Hashes for jsonobject_couchdbkit-0.9.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b99c791950b19f43a6f2def4e48c5b9170a823cf7ff1e37a2ddf4a68c3f7b3e6
MD5 4dfd159480821934caf9f4a846378715
BLAKE2b-256 1a3afc9900e3a4ac52e13c52ade6675584d7a6978fa8268fae4131c0dbca1222

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page