It's basically a little couch
zabuton is a CouchDB view server for Python.
If you already know what that means, I have nothing else to explain. If you don't, it's probably not useful to you (yet).
It exists because I was not happy with the alternatives. Licensed under Apache License, Version 2.0.
No releases yet. Grab the latest git version here: zabuton.py
git repository at http://yangman.ca/git/zabuton.
zabuton is a single, self-contained Python script. Requires python-2.6.
Consult the CouchDB page on View Server on configuring view servers.
ZABUTON IS NOT SANDBOXED: ANY AND ALL PYTHON SCRIPTING FUNCTIONS ARE EXPOSED TO COUCHDB. BEFORE DEPLOYING THIS ANYWARE, MAKE ABSOLUTELY CERTAIN YOU UNDERSTAND THE RISKS ASSOCIATED WITH USING A VIEW SERVER LIKE ZABUTON. IF THE VULNERABILITIES ARE NOT ALREADY OBVIOUS TO YOU, DO NOT DEPLOY IT!.
##
## Map function example
##
# You can import things
import math
from json import dumps as dumps_json
# Even do some initialization
what_to_say = "zabuton"
# Designate a function as the mapper using this decorator
# If there's only a single function definition, this can be omitted
# (But be careful: `from module import function` also defines a function)
@map_function
def map(doc):
# Use emit(), just like the JavaScript interface
emit(doc['_id'], what_to_say)
# Log a message
log("Comfy")
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##
## Reduce function example
##
# Still works
rereducer = sum
# You can define reduce and rereduce functions separately
@reduce_function
def reduce(values):
# values is a list of [[key, id], value]
return len(values)
# Name the function whatever you want; just make sure to decorate it
@rereduce_function
def silly_rabbit(values):
# Here, values is simply a list of values
return rereducer(values)
#----------------------
## Don't care for convenience? Here's the hard way to define reduce
# Like @map_function, decorator can be omitted
@allreduce_function
def allreduce(values, rereduce):
log("Who needs convenience?")
if not rereduce:
return len(values)
else:
return sum(values)
Of course, this is subject to change without notice at my whim (or by a very persuasive argument). The input to reduce(), in particular, could be neater...
Email me: yang@yangman.ca
I'm also on identi.ca (@yangman) and Twitter (@yangaroo).