title: Getting started
page_type: blog

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":/docs/api/  documentation.

If you have not installed couchdbkit yet, follow instructions on "download page":/download.html . Once you've done, you can write your first CouchDB document:

<pre class="code prettyprint">
 import datetime
 
 from couchdbkit import *
 
 class Greeting(Document):
      author = StringProperty()
      content = StringProperty()
      date = DateTimeProperty()
</pre>

h2. Store the submitted Greetings

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

<pre class="code prettyprint">
 
 # 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()
</pre>

Note: You can just use the <code>db.save</code> method to save any <code>Greeting</code> object.  


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:

<pre class="code prettyprint">
 greet.author = u"Benoît Chesneau"
 greet.save()
</pre>

Here we updated the author name.

h2. Dynamic properties

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

<pre class="code prettyprint">
 greet.homepage = "http://www.e-engura.org"
 greet.save()
</pre>

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

h3. 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 :

<pre class="code prettyprint">
 mkdir -p ~/Work/couchdbkit/example/_design/greeting/views/all
</pre>

In this folder we edit a file `map.js`:

<pre class="code prettyprint">
 function(doc) { 
   if (doc.doc_type == "Greeting") 
    emit(doc._id, doc); 
 }
</pre>

On "Textmate":http://macromates.com, you have:

!/images/gettingstarted.png(couchdbkit textmate screen)!

A system will be provided to manage view creation and other things. As some noticed, this system works like "couchapp":http://github.com/couchapp/couchapp/tree/.

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

<pre class="code prettyprint">
 from couchdbkit.designer import push

 push('/path/to/example/_design/greeting', db)
</pre>

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

<pre class="code prettyprint">
 greets = Greeting.view('greeting/all')
</pre>
