CherryPy is sweet !

Some quick questions:

Are you looking for fast, fun, stable HTTP, WSGI web server?

Faster development using Python?

Object oriented ?

Do you want to run multiple HTTP servers at once (on multiple ports).

Command line options ?

Easy configuration ?

Built in caching, encoding, sessions, authorizations. static contents ?

YES“, CherryPy is sweet. It allows developers to build web applications in much the same way they would build any other object-oriented Python program. This results in smaller source code developed in less time.
You can download the latest version from here.
Example:

import cherrypy
import json

class Application(object):
    @cherrypy.expose
    def hi(self, *args):
        if not args:
            raise cherrypy.HTTPError(400, "no args.")
        elif len(args) == 1:
            m={}
            m['message'] = "Hey " + args[0]
            return json.dumps(m)
        else:
            raise cherrypy.HTTPError(400, "Something is fishy")
root = Application()

cherrypy.server.socket_host = '0.0.0.0'
cherrypy.server.socket_port = 8080
cherrypy.quickstart(root, '/')

Save and Run the script: python cherry.py

ENGINE Started monitor thread '_TimeoutMonitor'.
ENGINE Started monitor thread 'Autoreloader'.
ENGINE Serving on 0.0.0.0:8080
ENGINE Bus STARTED

Click here to see the output.(http://localhost:8080/hi/govil)

{"message": "Hey govil"}

Sources: http://cherrypy.org/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s