Quite often, you will need to render the output of your application using a protocol other than HTML; for example, JSON or XML.

weppy can help you expose those services with the service decorator:

from weppy import App
from import service

app = App(__name__)

def f():
    # your code

The output will be automatically converted using the required service (JSON in this example).

– awesome. But, what if I need to expose several function with a service? Should I decorate every function?
you can use the provided handler, dude

weppy also provides a ServiceHandler object so you can create an AppModule with all the functions you want to expose with a specific service and add the handler to the module:

from weppy import AppModule
from import ServiceHandler
from myapp import app

api = AppModule(app, 'api', __name__)
api.common_handlers = [ServiceHandler('json')]

def a():
    # code

def b():
    # code

So, which are the available services? Let's see them.


Providing a JSON service with weppy is quite easy:

def f():
    l = [1, 2, {'foo': 'bar'}]
    return dict(status="OK", data=l}

The output will be a JSON object with the converted content of your python dictionary:

    "status": "OK",
    "data": [
            "foo": "bar",

To provide an XML service, just decorate your function using the next line instead:


Obviously, the syntax for using ServiceHandler is the same as in the first example:

# providing a JSON service handler

# providing an XML service handler