Getting Started

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

If you have not installed py-simplecouchdb yet, the installation docs will get you started. Once you’ve done, you can write your first CouchDB document:

from simplecouchdb import schema

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

See also

Schema Reference

Store the submitted Greetings

import datetime
from simplecouchdb import Server

server = Server()

try:
    db = server.create_db("greetings")
except:
    db = server['greetings']


greet = Greeting(
    author="Benoit",
    content="Welcome to simplecouchdb world",
    date=datetime.datetime.utcnow()
)

greet.save(db)

Now your greet document is saved in db. You could simple update it :

greet.content = "Welcome to CouchDB"
greet.save(db)

Do you want to add a property ? Easy:

greet.homepage = "http://www.e-engura.org"
greet.save(db)

Now you just add homepage property to your document.

Get all greetings

First wee need to create a view and save it in db (see Views classes for more informations), we add a simplecouchdb.schema.ViewProperty to our Document schema:

class Greeting(schema.Document):
    ...
    all = schema.ViewProperty("greeting", map_fun="""function(doc)
        { if (doc.doc_type == "Greeting") emit(doc._id, doc); }""")

greets = Greeting.all.get(db)

That’s it you now get all greets.

To go further

Have a look on

Enjoy :)