This article simply narrated the Python operation Couchdb method, shares for everybody reference. The specific methods are as follows:
1. Install the Python couchdb library:
https://pypi.python.org/pypi/CouchDB/0.10
2. Connecting to the server
>>> import couchdb
>>> couch = couchdb. Server (' http://example.com:5984/')
3. Create a Database
>>> db = couch.create (' Test ') # New database
>>> db = couch[' mydb '] # using a database that already exists
4. Create the document and insert it into the database:
>>> doc = {' foo ': ' Bar '}
>>> Db.save (DOC)
(' E0658cab843b59e63c8779a9a5000b01 ', ' 1-4c6114c65e295552ab1019e2b046b10e ')
>>> doc
{' _rev ': ' 1-4c6114c65e295552ab1019e2b046b10e ', ' Foo ': ' Bar ', ' _id ': ' E0658cab843b59e63c8779a9a5000b01 '}
The Save () method returns the ' _id ', ' _rev ' field
5. Querying the database by ID
>>> db[' e0658cab843b59e63c8779a9a5000b01 ']
<document ' e0658cab843b59e63c8779a9a5000b01 ' @ 1-4c6114c65e295552ab1019e2b046b10e ' {' foo ': ' Bar '}>
6. Update the document:
>>> data = db["5fecc0d7fe5acac6b46359b5eec4f3ff"]
>>> data[' billseconds '] = 191
>> > Db.save (data)
(U ' 5fecc0d7fe5acac6b46359b5eec4f3ff ', U ' 3-6b8a6bb9f2428c510dcacdd5c918d632 ')
7. Traverse the Database
>>> for ID in db: ... Print ID
...
' E0658cab843b59e63c8779a9a5000b01 '
8. Delete the document and clean the database
>>> Db.delete (DOC)
>>> couch.delete (' test ')
I hope this article will help you with your Python programming.