You are previewing CherryPy Essentials.
O'Reilly logo
CherryPy Essentials

Book Description

Design, develop, test, and deploy your Python web applications easily

  • Walks through building a complete Python web application using CherryPy 3

  • The CherryPy HTTP:Python interface

  • Use CherryPy with other Python libraries

  • Design, security, testing, and deployment

In Detail

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.

This book covers the CherryPy library for Python web development from its history and installation through its main features and core concepts to its integration with Python and other products to construct, test, and deploy a sample photoblog application. The author Sylvain Hellegouarch is dedicated to the development of free software projects and has been coordinating and administrating the community efforts around the CherryPy project since 2004. The approach based on an example application introduces many other common Python libraries, providing transferable skills also relevant for non-web Python projects.

Table of Contents

  1. Copright
  2. Credits
  3. About the Author
  4. Acknowledgement
  5. About the Reviewers
  6. Preface
    1. What This Book Covers
    2. What You Need for This Book
    3. Who is This Book for
    4. Conventions
    5. Reader Feedback
    6. Customer Support
      1. Downloading the Example Code for the Book
      2. Errata
    7. Questions
  7. 1. Introduction to CherryPy
    1. Overview
    2. History of CherryPy
    3. The Community
    4. CherryPy Project Strengths
    5. Beyond CherryPy
    6. Through the Book
    7. Summary
  8. 2. Download and Install CherryPy
    1. Requirements
    2. Overview
    3. Installation from a Tarball
    4. Installation through Easy Install
    5. Installation from Subversion
    6. Testing your Installation
    7. Keeping CherryPy Up to Date
    8. Summary
  9. 3. Overview of CherryPy
    1. Vocabulary
    2. Basic Example
    3. Built-In HTTP Server
    4. Internal Engine
    5. Configuration
    6. Object Publisher Engine
    7. Library
      1. The Autoreload Feature
      2. The Caching Module
      3. The Coverage Module
      4. The Encoding/Decoding Module
      5. The HTTP Module
      6. The Httpauth Module
      7. The Profiler Module
      8. The Sessions Module
      9. The Static Module
      10. The Tidy Module
      11. The Wsgiapp Module
      12. The XML-RPC Module
    8. Tools
    9. Error and Exception Handling
    10. Summary
  10. 4. CherryPy in Depth
    1. HTTP Compliance
    2. Multiple HTTP Servers
    3. Multi-Threaded Application Server
    4. URI Dispatching
      1. HTTP Method Dispatcher
      2. Routes Dispatcher
      3. Virtual Host Dispatcher
    5. Hook into CherryPy's Core Engine
    6. CherryPy Toolbox
      1. Basic Authentication Tool
      2. Caching Tool
      3. Decoding Tool
      4. Digest Authentication Tool
      5. Encode Tool
      6. Error Redirect Tool
      7. Etag Tool
      8. Gzip Tool
      9. Ignore Headers Tool
      10. Log Headers Tool
      11. Log Tracebacks Tool
      12. Proxy Tool
      13. Referer Tool
      14. Response Headers Tool
      15. Trailing Slash Tool
      16. XML-RPC Tool
      17. Toolbox
      18. Creating a Tool
    7. Static Resource Serving
      1. Using the Staticfile Tool to Serve a Single File
      2. Using the Staticdir Tool to Serve a Complete Directory
      3. Bypassing Static Tools to Serve Static Content
    8. WSGI Support
      1. Hosting a WSGI Application within the CherryPy WSGI Server
      2. Hosting a CherryPy WSGI Application within a Third-Party WSGI Server
    9. Summary
  11. 5. A Photoblog Application
    1. A Photoblog Application
    2. Photoblog Entities
    3. Vocabulary
    4. DBMSes Overview
      1. Relational Database Management System (RDBMS)
      2. Object-Oriented Database Management System (OODBMS)
      3. XML Database Management System (XMLDBMS)
    5. Object-Relational Mapping
      1. Python Object-Relational Mappers
    6. Photoblog Application Entity Modeling
      1. Mapping Entities
      2. Units and UnitProperties
      3. Associating Units
      4. The Sandbox Interface
    7. Querying Units
    8. Extending the Data Access Layer
    9. Summary
  12. 6. Web Services
    1. Traditional Web Development
      1. Separation of Concerns
    2. REST
    3. Uniform Resource Identifier
    4. HTTP Methods
    5. Putting it Together
    6. REST Interface through CherryPy
    7. Atom Publishing Protocol
    8. Atom XML-Document Format
    9. APP Implementation
    10. Summary
  13. 7. The Presentation Layer
    1. HTML
    2. XML
    3. XHTML
    4. CSS
    5. DHTML
    6. Templating
    7. Kid—The Templating Engine
      1. Overview
      2. Kid's Attributes
        1. XML-Based Templating Language
        2. Variable Substitution
        3. Conditional Statement
        4. Looping Mechanism
        5. Extensibility
        6. Other Attributes
    8. Photoblog Design Preparation
      1. Targetting the User Agent
      2. Tools
      3. Global Design Goals
      4. Design Directory Layout
      5. CherryPy—Encapsulating the Template Rendering Process
    9. Photoblog Design in Detail
      1. Basic Structure
    10. Mochikit
    11. Developing the Photoblog Design
      1. HTML Code
      2. Adding a Link
      3. Handling the End-User Actions
      4. Amending the Template
      5. Amending the CSS
      6. Let's be More Flexible...
    12. Summary
  14. 8. Ajax
    1. Rise of the Rich-Client Applications
    2. Ajax
      1. Ajax—Advantages and Drawbacks
      2. Behind the Scene: XMLHttpRequest
        1. Performing a GET Request
        2. Performing a Content-Negotiated GET Request
        3. Performing a POST Request
          1. Let's POST an XML Document
        4. Performing PUT, HEAD, or DELETE Requests
        5. Cookies
        6. Authentication using Digest or Basic Schemes
    3. JSON
    4. Applying Ajax to our Application
      1. Defining the Required Namespaces
      2. Implementing Namespaces
      3. Adding Methods to the Classes
      4. Method to Create a New Album
      5. Method to Update an Existing Album
      6. Method to Delete an Existing Album
    5. Summary
  15. 9. Testing
    1. Why Testing
    2. Planning a Test
    3. Common Testing Approach
    4. Unit Testing
      1. unittest
      2. doctest
    5. Unit Testing Web Applications
    6. Performance and Load Testing
    7. Functional Testing
      1. Application under Test
        1. Selenium Core
        2. Selenium IDE
        3. Selenium Remote Control
    8. Summary
  16. 10. Deployment
    1. Configuration
      1. CherryPy—Web and Engine Configuration System
      2. Photoblog Application Configuration System
    2. Deployment
      1. Apache with mod_rewrite Module
      2. Lighttpd with mod_proxy Module
      3. Apache with mod_python Module
      4. mod_python with WSGI Application
    3. SSL
      1. Creating a Certificate and a Private Key
        1. Using the CherryPy SSL Support
        2. Using the lighttpd SSL Support
        3. Using the Apache mod_ssl Support
    4. Summary
    5. Author's View