There are several CouchDB libraries for Python but I went with Couchdbkit. This decision was influenced by a post on the Cloudant discussion board stating Couchdbkit and Cloudant should work well together. So far, I have to agree.
The installation instructions for Couchdbkit are pretty straight forward. For the record, I'm using Python 2.6.6. I did find I needed to use restkit for HTTP resources. I set my sights low - I just wanted to get the program of Couchdbkit's Getting Started page to work. Username/password redacted to protect the innocent:
#! /usr/bin/env python
import datetime
from couchdbkit import *
from restkit import BasicAuth
class Greeting(Document):
author = StringProperty()
content = StringProperty()
date = DateTimeProperty()
server = Server('https://[username].cloudant.com/', filters=[BasicAuth('[usename]', '[password]')])
db = server.get_or_create_db("greeting")
Greeting.set_db(db)
greet = Greeting(
author="Benoit",
content="Welcome to couchdbkit world",
date=datetime.datetime.utcnow()
)
greet.save()
There are more exercises on the Getting Started page including an introduction to views. This worked as advertised with no need to change the supplied code.
No comments:
Post a Comment