Home > computers > programming > python | pythonmicrowebframeworks | About


  • Maturity : 10 years (2015)
  • No dependencies
  • Hello world
import cherrypy
class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True


Extra : works on Android.

Bottle (my favorite so far)

  • A single file
  • Hello World
from bottle import route, run, template

def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

Extra: nice routes.


  • Hello world
from circuits.web import Server, Controller

class Root(Controller):

   def index(self):
      return "Hello World!"

(Server(8000) + Root()).run()
  • Very componentized, components are litterally 'added' to your Server
from circuits.web import Server, Controller

class Root(Controller):

    def index(self):
        return "Hello World!"

(Server(8000) + Logger() + Root()).run()

We have just added a logger and a request handler to our http server

(Server(8000) + Static("/static", docroot="/home/joe/www/") + Root()).run()

We have just added a static route dispatcher to our app to serve static files (js, css, img etc.)

  • Easy WSGI integration.
from circuits.web.wsgi import Gateway
from circuits.web import Controller, Server

def foo(environ, start_response):
    start_response("200 OK", [("Content-Type", "text/plain")])
    return ["Foo!"]

class Root(Controller):
    """App Rot"""

    def index(self):
        return "Hello World!"

app = Server(("", 10000))
Gateway({"/foo": foo}).register(app)

Extra : Form names map directly to function arguments.

!/usr/bin/env python

from circuits.web import Server, Controller

class Root(Controller):
    html = """\
  <form action="submit" method="POST">
     <td><input type="text" name="firstName"></td>
     <td><input type="text" name="lastName"></td>

    def submit(self, firstName, lastName):
        return "Hello %s %s" % (firstName, lastName)

(Server(8000) + Root()).run()


  • URL to python method mapping (routes)
  • HTML creation library
  • FORM creation and processing library
  • A templating language (PTL)
  • Weired API
_q_exports = [ "doit1", "doit2", ("externalName", "doit3") ]

URIs are put in first level, then all the methods are put in a tuple. Why not create a list of two tuples for example ?

  def _q_index (request):

This is actually the name of a public method that can be rewritten to define the default method to call when no specific mapping exists for a certain URI. Why does it look like a private method ?


  • Hello World
from weblayer import Bootstrapper, RequestHandler, WSGIApplication

class Hello(RequestHandler):
    def get(self, world):
        return u'hello %s' % world

mapping = [(r'/(.*)', Hello)]

config = {
    'cookie_secret': '...', 
    'static_files_path': '/var/www/static',
    'template_directories': ['templates']

bootstrapper = Bootstrapper(settings=config, url_mapping=mapping)
application = WSGIApplication(*bootstrapper())

def main():
    from wsgiref.simple_server import make_server
    make_server('', 8080, application).serve_forever()

if __name__ == '__main__': # pragma: no cover

contact : @ychaouche yacinechaouche at yahoocom

QR Code
QR Code CherryPy (generated for current page)