What is CherryPy Python? – Introduction to CherryPy

By | September 25, 2021

Remi Delon created CherryPy in 2002, and it is one of the oldest Python web-framework. Like Flask, it is also a lightweighted Python framework with few dependencies.

What is CherryPy Python Framework?

CherryPy follows the pythonic way, and with its Object Orientation approach, it made it easy for developers to write and wrap web logic around HTTP protocols. The simplicity is the main asset of CherryPy, and it can use Object Relational Mapper (ORM), and templating languages extensions for database and templating.

Features of CherryPy Framework

Although CherryPy is not the most popular Python web framework, you should still know its features before learning it.

  1. It is one of the simplest Python web frameworks.
  2. It follows a modular approach to write web app logic.
  3. It comes with common web-app building tools like caching, encoding, session, authorizations, static content, and many more.
  4. It also provides a built-in test suite for rapid internal testing of web applications.
  5. It can support multiple Object Relational Mappers (ORM) for Data Bases access.
  6. It can also work with different templating languages such as Mako, Jinja, Genshi, CherryTemplate, etc.
  7. It is also known as an Object-Oriented web application framework and supports all of its properties like Data hiding and security.
  8. It is an open-source project and has 1.4K stars on its Github repo.
  9. It comes with a built-in production-ready HTTP server for development and deployment.
  10. As it follows Object Orientation concepts, we can use Inheritance in CherryPy for Data Reusability.

Get Started with CherryPy Python

It is a Python web framework, so it goes without saying Python should be installed on your system before you want to create or run a web Application using CherryPy.

CherryPy is an open-source third Party library, and we need to install it before wring or running its application.

To install CherryPy for our Python environment, we can use the pip install terminal command.

pip install cherrypy

Now let’s write our first CherryPy web application as app.py

Vamware

#app.py

import cherrypy
class HomePage(object):
    @cherrypy.expose
    def index(self):
        return "<h1>Hello World! Welcome To cherryPy</h1>"

if __name__=="__main__":
    cherrypy.quickstart(HomePage(),'/')

Now run the app.py as a Python script on your terminal or command prompt.

Vamware
C:\Users\ code>python app.py

[02/May/2021:12:09:25] ENGINE Listening for SIGTERM.
[02/May/2021:12:09:25] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[02/May/2021:12:09:25] ENGINE Set handler for console events.
[02/May/2021:12:09:25] ENGINE Started monitor thread 'Autoreloader'.
[02/May/2021:12:09:25] ENGINE Serving on http://127.0.0.1:8080
[02/May/2021:12:09:25] ENGINE Bus STARTED

When you run the Python script, it will activate a local server, and you can visit http://127.0.0.1:8080 on your browser to see the output.

Conclusion

CherryPy is a minimal Python web framework. It is designed to follow the Pythonic simpler and modular way to design web applications. However, it is not the most popular Python web framework still it one of the best alternatives for the Flask. We can build simple Create Update Retrieve and Delete (CURD) web applications with ease with its minimal approach.

People are also reading: 

Leave a Reply

Your email address will not be published.