Skip to content

python & couchdb sample

Lacking any good examples of how to use python’s couchdb module, I’ve managed to make pretty impressive progress (for me) on a 4th of July holiday.

I’ll try to recreated it here for others although I know it’ll be incomplete.

Consider it a syntactical example;

import couchdb
s = couchdb.Server(’http://localhost:5984/’) ##why can’t it default to this?
db = s['stock_values']
ids = []
stock_values = {}
for doc in db:

ids.append(doc)
d = db[doc]
stock_values[d['symbol']] = d['historical_data']

More good examples are in the code;

http://code.google.com/p/couchdb-python/source/browse/trunk/couchdb/client.py?r=61

{ 3 } Comments

  1. chris | July 5, 2008 at 8:10 pm | Permalink

    why do you need a database for your couches? do you really have that many to keep track of?

  2. jay | July 6, 2008 at 5:01 pm | Permalink

    Silly Chris,
    couchdb is for geeks!

    http://incubator.apache.org/couchdb/docs/overview.html

    Picture simplicity as an evolutionary trait and apply it to databases.
    We’re not yet sure if it’ll yield a failed branch of a full trunk but it’s a great exploration!

  3. jay | October 18, 2008 at 10:40 pm | Permalink

    Here’s how to create a named document instead of using db.create()

    db["foo"] = { ’something’ : “else”, ‘ok’: “works”}

{ 1 } Trackback

  1. [...] you’ve seen from my previous posts I’ve been playing with python, couchdb and been working my way through the “Programming Collective Intelligence” book. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *