Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install centipede

How to install centipede

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install centipede
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.2.5 Available View build log
0.2.3 Available View build log
0.2.2 Available View build log
0.2.1dev Available View build log
0.2dev Available View build log
0.1.1dev Available View build log
Windows (64-bit)
0.2.5 Available View build log
0.2.3 Available View build log
0.2.2 Available View build log
0.2.1dev Available View build log
0.2dev Available View build log
0.1.1dev Available View build log
Mac OS X (10.5+)
0.2.5 Available View build log
0.2.3 Available View build log
0.2.2 Available View build log
0.2.1dev Available View build log
0.2dev Available View build log
0.1.1dev Available View build log
Linux (32-bit)
0.2.5 Available View build log
0.2.3 Available View build log
0.2.2 Available View build log
0.2.1dev Available View build log
0.2dev Available View build log
0.1.1dev Available View build log
Linux (64-bit)
0.2.5 Available View build log
0.2.3 Available View build log
0.2.2 Available View build log
0.2.1dev Available View build log
0.2dev Available View build log
0.1.1dev Available View build log
 
Author
License
FreeBSD
Imports
Lastest release
version 0.2.5 on May 23rd, 2012

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 from urlrelay.

Installation

$ pip install centipede

Defining handlers

With Centipede you expose functions to urls. Functions either return a string or a tuple. A string is treated as the document body, http status is set to 200 OK and returned to the browser. Should you return a tuple, status code, body and headers are 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 arguments

The expose decorator looks like this:

expose(url_pattern, method='GET', content_type='text/html', charset='UTF-8')

Request

The parameter passed to the functions exposed (request in the examples above) is the WSGI environ dictionary. For convenience the query string parameters and form data parameters are packed into environ's params and data keys.

Query string data

For convenience, query string parameters are available as a dictionary in environ's params key. Both key and value are unquoted using urllib.unquote. Unquoted parameters are passed to the params_raw key.

Form data

For convenience, form data are available as a dictionary in environ's data key. Both key and value are unquoted using urllib.unquote_plus. Unquoted parameters are passed to the data_raw key.

Templates

I 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 files

For 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 passing app a parameter:

app('path/to/static')

Deployment

For deployment it is a good idea to run your centipede application behind a good WSGI server. There is a bunch. Gunicorn is good. I usually end up running uwsgi behind nginx.

Changelog

0.2.5
  • Separated query string params and form data
  • Form data in data key
  • Query string params in params key
  • Improved error handling for unpacking params (needs more work)
0.2.4
  • Added urllib.unquote_plus for POST parameters.
  • Added params_raw key to environ in case urllib.unquote mess up your parameters.
0.2.3
  • Added params key to environ for easy parameter access.
  • Added urllib.unquote for params

enjoy.

Subscribe to package updates

Last updated May 23rd, 2012

Download Stats

Last month:6

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.