CherryPy → CherryPy – Introduction – Camposha

CherryPy

CherryPy

CherryPy – Introduction

CherryPy is a minimalistic, pythonic and object oriented web framework.

Web Frameworks normally allow developers to develop web applications without getting their hands dirty with low level details such as HTTP protocols and threading concepts.

CherryPy is a battle-tested framework that has existed in the industry for more than a decade.

However, it’s very modern and allows us build applications the way you would build any Object Oriented application in Python.

This makes it very attractive especially for those people coming from system or more general-purpose languages like C++, Java and Python.

The code written in CherryPy is one of the cleanest and attractive you’ll ever see. Python is always a language considered to be for artists due to its beauty, and certainly CherryPy more than fits that profile.

CherryPy is considered minimalistic in that it wraps the HTTP protocol and does not otherwise offer much more than what is defined in the RFC 7231. However, this makes it very extensible and also easy to grasp. Extensible can be done via packages.

We are Building a Vibrant YouTube Community

We have a fast rising YouTube Channel of friends. So far we’ve accumulated almost 3 million agreggate views and more than 10,000 subscribers as of the time of writing this. Here’s the Channel: ProgrammingWizards TV.

Please go ahead subscribe(free obviously) as well. If you have a question or a comment you can post there instead of in this site.People are suggesting us tutorials to do there so you can too.

Features

  1. CherryPy allows us write web applications in Object Oriented manner.
  2. CherryPy includes a reliable HTTP/1.1 compliant, WSGI thread-pooled web server. This makes it a viable production ready web server just like it is a web framework.

By being HTTP/1.1 compliant, this makes cherryPy take advantage of latest features HTTP features that allow construction of practical information systems.

HTTP as you know stands for HyperText Transfer Protocol, and is an application-level protocol for distributed, collaborative and hypermedia information systems.

HTTP has been powering the web for almost 3 decades since the inception of World Wide Web by Sir Tim Berners Lee.

  1. Thirdly CherryPy is easy to run on multiple HTTP servers via different ports at once.
  2. CherryPy is enhanced with powerful built-in tools for caching, data encoding,sessions, authentication, static content etcetra.
  3. CherryPy can run on Python 2.7+,3.1+, PyPy, Jython and even Android via the SL4A.
  4. CherryPy is open source and is distributed under the BSD license.

CherryPy website is here.

Object Relational Mappers

The following are some of the Object Relational Mappers that can be used with CherryPy.

  1. SQLAchemy – an ORM for python applications.
  2. SQLObject – an ORM that provides an object interface to a database.
  3. Storm – the ORM made by Canonical Ltd, who are makers of Ubuntu.

Templating Languages

The following are some of the templating languages that can be used with CherryPy:

  1. Jinja – General purpose tempating language.
  2. Mako – Template language written in Python.
  3. Cheetah – Open source template engine.
  4. CherryTemplate – a templating language for CherryPy.
  5. Genshi – XML templating language.

Hello World

Here’s a simple Hello World in CherryPy.

import cherrypy

class MrHello(object):
    def index(self):
        return "Mr Hello says: `Hello World!`"
    index.exposed = True

cherrypy.quickstart(MrHello())

This will start the CherryPy server at a port probably 8080e.g

ENGINE Serving on http://127.0.0.1:8080

Pount that URL browser and you’ll see a message like this:
RESULT

Mr Hello says: `Hello World!`

Best Regards.

Leave a Reply

Your email address will not be published. Required fields are marked *

X