Package: centipede
Centipede is a WSGI microframework with a simple decorator based router. It’s strength is that it models the technology in use and tries not to confuse developers with complex patterns and tricks. It inherits strongly fromurlrelay.Installation$ pip install centipedeDefining handlersWith Centipede you expose functions to urls. Functions either return astringor atuple. A string is treated as the document body, http status is set to200 OKand returned to the browser. Should you return a tuple,status code,bodyandheadersare expected. The expose decorator also supports a few arguments.from centipede import expose, app

@expose('^/$')
def index(request):
    """ Simple Hello
    """
    return 'Hello IgglePigglePartyPants!'

@expose('^/google$')
def index(request):
    """ A redirect
    """
    return (307, '', {'Location':'http://google.com'})

import json

@expose('^/twitter','POST',content_type='application/json')
def tweet_post(request):
    """ Tweet
    """
    data  = request['data']
    text  = data['text']
    user  = data['user']
    tweet = magic.tweet(text, user)
    return json.dumps(tweet)

@expose('^/twitter/(?P<tweet>\w+)$','GET',content_type='application/json')
def twitter(request):
    """ Get a tweet
    """
    id    = req['wsgiorg.routing_args'][1]['tweet']
    meta  = request['params']['metadata']
    tweet = magic.get_tweet(id, meta=meta)
    return json.dumps(tweet)

application = app()Expose argumentsThe expose decorator looks like this:expose(url_pattern, method='GET', content_type='text/html', charset='UTF-8')RequestThe parameter passed to the functions exposed (requestin the examples above) is the WSGIenvirondictionary. For convenience thequery string parametersandform dataparameters are packed into environ’sparamsanddatakeys.Query string dataFor convenience, query string parameters are available as a dictionary in environ’sparamskey. Both key and value are unquoted usingurllib.unquote. Unquoted parameters are passed to theparams_rawkey.Form dataFor convenience, form data are available as a dictionary in environ’sdatakey. Both key and value are unquoted usingurllib.unquote_plus. Unquoted parameters are passed to thedata_rawkey.TemplatesI would recommend keeping your html templates static on the client side and use a javascript template library. But if you really need some server side templating, have a look at mako.Static filesFor production you should always host your static files directly from the webserver or a varnish cache or something. But for development purposes you can have centipede serve your static files by passingappa parameter:app('path/to/static')DeploymentFor deployment it is a good idea to run your centipede application behind a good WSGI server. There is abunch.Gunicornis good. I usually end up runninguwsgibehind nginx.Changelog0.2.5Separated query string params and form dataForm data indatakeyQuery string params inparamskeyImproved error handling for unpacking params (needs more work)0.2.4Added urllib.unquote_plus for POST parameters.Addedparams_rawkey to environ in case urllib.unquote mess up your parameters.0.2.3Addedparamskey to environ for easy parameter access.Added urllib.unquote for paramsenjoy.