Book Review: CherryPy Essentials

I recently created a server application to share Felix memories/glossaries over a local network. After a simple test application, I was confident that CherryPy would serve my needs, so I bought CherryPy Essentials (Sylvain Hellgegouarch) and started hacking.





The story of a website

The book uses a practical-minded, show-me-the-code style that I personally like. The book tells the story of a website, starting with an introduction to CherryPy, then walking us through the creation of a sophisticated Web 2.0 website, adding more elements as our understanding grows.

While I found the style of taking us through the development of a website useful, this approach has an obvious weakness: if you don't use the same components as the author, the book will be less relevant. For example, the author chooses Dejavu for his ORM, while I prefer SQLAlchemy; he chooses Kid for his templating engine, while I prefer Mako; and he chooses MochiKit for his JavaScript library, while I prefer jquery.

While this prevented me from using the book's code whole cloth, it did show me how to build a website the CherryPy way, using CherryPy's fantastic features and integrating them with the other technologies used in a modern Web application. In all I'm quite pleased with the value I got out of the book.

Contents

Chapter 1: Introduction to CherryPy

Chapter 2: Download and Install CherryPy

Chapter 3: Overview of CherryPy

Chapter 4: CherryPy in Depth

Chapter 5: A Photoblog Application

Chapter 6: Web Services

Chapter 7: The Presentation Layer

Chapter 8: Ajax

Chapter 9: Testing

Chapter 10: Deployment

Chapter 1: Introduction to CherryPy

This chapter provides some introduction to CherryPy's history and community. It can be safely skipped by the impatient.

Chapter 2: Download and Install CherryPy

Not too much of interest here either. If you can find the book, I'm sure you can find CherryPy.

Chapter 3: Overview of CherryPy

Here's where things start getting interesting. We start with a simple "shout" style application, then walk through the anatomy of a basic CherryPy application: configuration, static files, URL routing, and page handlers.

The author also provides a list of the built-in library modules, which I found to be fairly useless since he doesn't tell us how to use them or even really much about what they might be good for.

Chapter 4: CherryPy in Depth

True to its title, this chapter talks in depth about the various capabilities and tools provided with CherryPy, including material on extending and hooking the CherryPy engine. If you've got experience developing websites, chapters 3 and 4 are really all you need to get cracking on a cool website with all the fixings.

Chapter 5: A Photoblog Application

For the remainder of the book, we'll be building a photo blogging application, fully Web 2.0 buzzword compliant with web services, JavaScript, and AJAX goodness.

The chapter provides a high-level outline of the application we'll be building, and then discusses some of the various ORMs available for Python.

Chapter 6: Web Services

This cool chapter describes how to build Web services (including RESTful services) using CherryPy. This served as a major inspiration for creating the API to my server, although I decided not to use REST.

Chapter 7: The Presentation Layer

This chapter goes over templating libraries for Python (the only thing more numerous in Python than templating libraries are Web frameworks) and how to integrate them with CherryPy, then settles on Kid as the engine to use for the application.

Chapter 8: Ajax

Although the author uses MochiKit as his JavaScript library, he describes the AJAX communication process at a fairly low level, so it was easy to transfer the concepts over to jquery. After briefly describing JSON as the mechanism for transferring data between JavaScript and Python, the chapter goes on to describe how we'll be using AJAX in our photo blogging application.

Chapter 9: Testing

You've got to give props to a framework book that devotes a chapter to testing. As with other components, although I prefer nose and mechanize for unit/web testing to the author's unittest and webtest, the concepts were what mattered and I had no trouble following along.

I also appreciated the section on performance/load testing using FunkLoad, as well as function testing with Selenium, which I wasn't very familiar with.

Chapter 10: Deployment

This chapter is also pure gold in a framework book. It discusses the various deployment and configuration options, including deploying behind Apache and lighttpd. I found the section on supporting SSL to be particularly helpful, as my next step for my server will be hosting it myself via SSL.

Conclusion

This book is a great practical guide to building websites with CherryPy, using best practices for the framework and getting the most out of the huge array of functionality that it provides.

The Packt Publishing Ebook

I bought this book as a PDF from Packt Publishing. I prefer having programming books in electronic format, because I typically read them at my computer while experimenting with the code in the book. And since I live in Japan, the electronic format is also a great way to get my grubby hands on technical books quickly and cheaply.

Packt ebooks, I found, have an annoying security feature: copy and paste is disabled, thwarting my preferred tactic of copying and pasting code snippets to run, and terms to google. Sure, the code samples are provided, but that adds a lot of hassle to what should be a simple operation.

I wish Packt would discontinue this practice. It only hurts paying customers, since the pirates will no doubt have little trouble stripping out that protection and repackaging the book in any format they like.