CherryPy is a popular framework of Python. Using CherryPy, web applications can be built in a faster and more reliable way. It is also called a web application library. It is known for its simplicity as it is based on object-oriented Python programming, resulting in smaller source code in less time. It is one of the oldest frameworks of Python, the very first version being released in June 2002. This framework is mainly for the developers who want to create portable database-driven web application using Python, as it provides Create, Retrieve, Update and Delete functionalities.
Note: Before proceeding with CherryPy, you should have a good understanding of Model-view-controller and Object-Oriented-Programming.
Why CherryPy?
As we know, Object-Oriented-Programming in itself has many advantages. The Extensive Support Libraries in Python and its Open Source and Community Development along with OOP gives a strong base to CherryPy.
- Simplicity: The complexity is reduced as the software object model objects and hence the code structure is very legible.
- Modular: Each object forms a separate entity whose internal workings are decoupled from other parts of the system. This enables us to consistently improve our solutions and it leads to efficiency in development through reuse.
- Modifiability: Minor changes can be easily made as changes inside a class do not affect any other part of a program.
- Extensibility: New objects can be introduced and existing ones can be modified to add new features or update existing ones.
- Data Re-usability: The objects can be used in other programs.
- Data Redundancy: Inheritance can be applied if you need a same functionality in multiple class.
- Data hiding: Implementation details are hidden from other modules and other modules has a clearly defined interface.
- Security: Using data hiding and abstraction we are providing necessary data only it mean we are maintaining security.
- Open Source: It is a community-maintained, open-source project hosted at Github.
- Deployment: It binds HTTP protocol into an API and includes its own production-ready HTTP server for hosting applications in a cost effective manner.
The project founder, Remi Delon wished to make CherryPy as Pythonic as possible so that the developer can use the framework as any regular Python module.
Take a look at the most basic application, a “Hello World” program with CherryPy:
import cherrypy class Root( object ): @cherrypy .expose def index( self ): return "Hello World !" if __name__ = = '__main__' : cherrypy.quickstart(Root(), '/' ) |
Output:
CherryPy takes an HTTP request and locates the most appropriate Python function or method that matches the request’s URL.