Table of contents
1.
Introduction 📝
2.
Features of cherryPy 🎯
3.
Application hosting - single and multiple ⚙️
3.1.
🔖Single application
3.2.
🔖Multiple applications
4.
Frequently Asked Question❓
4.1.
What is cherrpy?
4.2.
How to host single application in CherryPy?
4.3.
Is CherryPy free and open source?
4.4.
Is CherryPy a web server?
4.5.
What exactly is the CherryPy framework?
5.
Conclusion ✉️
Last Updated: Mar 27, 2024
Easy

Hosting one or more applications in cherryPy

Author Alok Pandey
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 📝

Have you heard the word cherryPy? No, it's not any fruit name, CherryPy is a Python web framework that provides a user-friendly interface to the HTTP protocol for Python developers. It's also known as a web application library. In this article, we will discuss Hosting one or more applications in cherryPy.We discuss hosting single and multiple applications separately.

Hosting one or more applications in cherryPy

Features of cherryPy 🎯

CherryPy is a Python web framework that provides a user-friendly interface to the HTTP protocol for Python developers. It's also known as a web application library. We know that there is a lot of advantage of object-oriented programming in itself. Here are certain features of cherry py listed below:

  • Cherry py is support oops programming so it has the advantages of using all the oops concepts like abstraction, encapsulation, inheritance, and polymorphism.
     
  • Cherry py is a lightweight framework which means it is smaller in size yet capable to do all the tasks smoothly.
     
  • Cherry py supports the extensive support of libraries which increases productivity.
     
  • Cherry py is a community-maintained, open-source project hosted on Github.
     
  • Cheery py binds the HTTP protocol into an API and includes its own production-ready HTTP server for cost-effective application hosting.

Application hosting - single and multiple ⚙️

An HTTP server is required to access a web application. CherryPy includes its own production-ready HTTP server. There are two ways to host an application with it. The simple one and the almost-as-simple one.

🔖Single application

Single Application

The simplest method is to use the cherrypy.quickstart() function. It requires at least one argument, the application instance to host. Two more options are available. First, specify the base path from which the application will be accessible. Second, you'll need a configuration dictionary or file to configure your application.
 

cherrypy.quickstart(Home())
You can also try this code with Online Python Compiler
Run Code


The above example indicates that your application will be accessible at http://hostname:port/
 

cherrypy.quickstart(Home(), '/home')
cherrypy.quickstart(Home(), '/home', {'/': {'tools.gzip.on': True}})
You can also try this code with Online Python Compiler
Run Code


The above two examples indicate that your blog application will be accessible at http://hostname:port/home. Furthermore, the last one provides application-specific settings.


Note

In the last case, notice how the settings are still relative to the application, rather than where it is made available, as indicated by the {'/': ... } rather than a {'/home': ... }

🔖Multiple applications

Multiple Application

The cherrypy.quickstart() method works well for a single application but does not support hosting multiple applications on the server. To accomplish this, use the cherrypy.tree.mount function as follows:

cherrypy.tree.mount(Home(), '/home', blog_conf)
cherrypy.tree.mount(Forum(), '/forum', forum_conf)
You can also try this code with Online Python Compiler
Run Code


Cherrypy.tree.mount, in simple terms, accepts the same parameters as cherrypy.quickstart() an application, a hosting path segment,, and a configuration. We can simply start the the application server by following command:

cherrypy.engine.start()
cherrypy.engine.block()
You can also try this code with Online Python Compiler
Run Code


Note:

Cherrypy.quickstart() and cherrypy.tree.mount are not mutually exclusive functions.For example, we can write the above lines as: 

cherrypy.tree.mount(Home(), '/home', home_conf)
cherrypy.quickstart(Forum(), '/forum', forum_conf)
You can also try this code with Online Python Compiler
Run Code

Frequently Asked Question❓

What is cherrpy?

CherryPy is a Python web framework that provides a user-friendly interface to the HTTP protocol for Python developers.

How to host single application in CherryPy?

For hosting single application on CherryPy we use cherrypy.quickstart() function.It requires at least one argument, the application instance to host.

Is CherryPy free and open source?

CherryPy is an open-source project, so contributions are welcome. If you're interested, you can fork CherryPy on GitHub and submit a pull request with your changes.

Is CherryPy a web server?

In Brief: CherryPy WSGI Web Server. It is a modular component that can serve any Python WSGI web application.

What exactly is the CherryPy framework?

CherryPy is an object-oriented web application framework that is written in Python. It is intended for the rapid development of web applications by wrapping the HTTP protocol, but it remains at a low level and does not provide much more than RFC 7231 defines.

Conclusion ✉️

In this article, we have extensively discussed Hosting one or more applications in cherryPy in detail. If you would like to learn more, check out our articles on
 

 

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enroll in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass