What is CherryPy Python? - Introduction to CherryPy

Posted in /  

What is CherryPy Python? - Introduction to CherryPy
vinaykhatri

Vinay Khatri
Last updated on June 16, 2024

    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. Simplicity is the main asset of CherryPy, and it can use Object Relational Mapper (ORM) and templating language extensions for databases and templates.

    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 writing 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 a third-party open-source 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 #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.

    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 of designing web applications. However, it is not the most popular Python web framework, it is still one of the best alternatives for Flask. We can build simple Create, Update, Retrieve, and Delete (CURD) web applications with ease with our minimal approach.

    People are also reading:

    FAQs


    CherryPy is an object-oriented web application framework for creating web applications using the Python programming language.

    CherryPy is a web application framework that comes with its own HTTP web server. So, it becomes easy to run CherryPy applications within minutes as it is self-contained.

    Yes, CherryPy is an open-source web framework. As a result, your contribution to the framework is always welcomed.

    MVC stands for Model-View-Controller. CherryPy follows the MVC architectural design pattern to create web applications.

    CherryPy is a object-oriented web framework used for creating web applications in Python rapidly.

    Leave a Comment on this Post

    0 Comments