Skip to content

Instantly share code, notes, and snippets.

@johnzablocki
Created March 26, 2012 22:50
Show Gist options
  • Save johnzablocki/2210390 to your computer and use it in GitHub Desktop.
Save johnzablocki/2210390 to your computer and use it in GitHub Desktop.
Couchbase Python Client Library View REST API
from couchbase.rest_client import RestConnection
doc = """
{
"_id": "_design/breweries",
"views": {
"all_breweries": {
"map": "function(doc) { if (doc.type == 'beer') emit(null, doc) }"
}
}
}
"""
print doc
def main():
server_info = { "ip" : "127.0.0.1", "port" : 8092, "username" : "", "password" : "", "couchApiBase" : "http://127.0.0.1:8092/" }
rest = RestConnection(server_info)
print "** create_design_doc **"
print rest.create_design_doc("default", "breweries", doc)
print
print "** get_design_doc **"
print rest.get_design_doc("default", "breweries")
print
print "** get_view **"
print rest.get_view("default", "breweries", "all_breweries")
print
print rest.delete_design_doc("default", "breweries")
print "** delete_design_doc **"
print
print "** view_results **"
print rest.view_results("default", "beers", "beers_by_name", {"start_key" : "T"}, limit=2)
print
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment