Introduction to CherryPy

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.

cherrypy

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.

  1. Simplicity: The complexity is reduced as the software object model objects and hence the code structure is very legible.
  2. 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.
  3. Modifiability: Minor changes can be easily made as changes inside a class do not affect any other part of a program.
  4. Extensibility: New objects can be introduced and existing ones can be modified to add new features or update existing ones.
  5. Data Re-usability: The objects can be used in other programs.
  6. Data Redundancy: Inheritance can be applied if you need a same functionality in multiple class.
  7. Data hiding: Implementation details are hidden from other modules and other modules has a clearly defined interface.
  8. Security: Using data hiding and abstraction we are providing necessary data only it mean we are maintaining security.
  9. Open Source: It is a community-maintained, open-source project hosted at Github.
  10. 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

import cherrypy
  
  
class Root(object):
    @cherrypy.expose
    def index(self):
        return "Hello World !"
  
if __name__ == '__main__':
   cherrypy.quickstart(Root(), '/')

chevron_right


Output:

cherrypy-hello-world

CherryPy takes an HTTP request and locates the most appropriate Python function or method that matches the request’s URL.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.