Book Image

CherryPy Essentials: Rapid Python Web Application Development

By : Sylvain Hellegouarch
Book Image

CherryPy Essentials: Rapid Python Web Application Development

By: Sylvain Hellegouarch

Overview of this book

<p>CherryPy is a Python library for web development that allows developers to build web applications in the same way as any other object-oriented Python program. Enriched by several years of active development, it has become one of the most established toolkits for building solid and high-performance web applications in Python. CherryPy abstracts the complex low-level HTTP protocol into an easy-to-use interface that respects Python idioms. The library aims at being simple to learn for a beginner while offering the most advanced features to fluent Python developers. For these reasons CherryPy was chosen to be at the heart of the popular and feature-rich TurboGears web framework. CherryPy-powered web applications are stand-alone Python applications with their own embedded multi-threaded web server, but can also run behind Apache or IIS for scalability.</p>
Table of Contents (17 chapters)
CherryPy Essentials
Credits
About the Author
Acknowledgement
About the Reviewers
Preface
Index

Traditional Web Development


Most web applications use the same base URI to handle the serving of resources and the manipulation of resources. For instance, it's common to find something such as the following:

URI

Request Body

HTTP Method

Operation

/album/

N/A

GET

Fetch all albums

/album/?id=12

N/A

GET

Fetch the album with the ID 12

/album/edit?id=12

N/A

GET

Return a form to perform an action on a resource

/album/create

title=Friends

POST

Create an album

/album/delete

id=12

POST

Delete the album with the ID 12

/album/update

id=12&title=Family

POST

Update the album with the ID 12

Within an application hosted with CherryPy, this could be translated into:

class Album:
     @cherrypy.expose
     def index(self, id=None):
         # returns all albums as HTML or the one 
         # requested by the id parameter if provided

     @cherrypy.expose
     def edit(self, id=None):
         # returns an HTML page with a form to perform 
         # an action on a resource...