Introduction💁
Python is a multi-purpose programming language. Its code is mostly emphasized on readability with the usage of a significant amount of indentation.
The CherryPy is a python framework that is used for web application development. CherryPy is used to wrap the HTTP protocols to provide more rapid web development.

CherryPy
Now that we know what cherryPy is, let us look at a few of its advantages and disadvantages.
Advantages
-
CherryPy has various built-in plugins.
-
CherryPy supports various HTTP servers simultaneously.
-
CherryPy provides built-in tools for profiling and testing.
-
CherryPy is HTTP/1.1 compliant and supports a thread pooled WSGI web server.
-
CherryPy provides multiple compatibilities with multiple HTTP servers.
- CherryPy has various built-in tools to perform tasks such as authorization, encoding, sessions, and caching.
Disadvantages
- CherryPy is a fairly outdated framework, thus it is very hard to find documentation for it. Users might have to look for hours to find proper documentation for a particular feature.
Pre-Request Functions✨
The most basic task in any web application is to tailor the request’s processing to the runtime context. We can perform this task using tools in CherryPy. There are three basic parts of Tools in CherryPy,
- Static Tools
- Tools Ordering
- Toolbox
But, before we move on to tools, we need to understand a little about hook points in CherryPy. So in this blog, we will discuss all about the various hook points present in CherryPy.
Hook Points🪝
Hook points are basically a point during the response or request processing. Hook points are used to alter the flow of code or some functionality during, before, or after the execution of the code. There are various hook-points that can be used to hang your tools in CherryPy. Let us look at some of these hook points,
-
on_start_resource: This is the earliest hook. It is used after the headers, and request lines have been processed, and the header has set the request.config and the request.handler.
-
before_handler: This tool is used right before the request.handler is set.
-
before_request_body: These hooks are run right before the request body is processed.
-
on_end_resource: This hook point is run after all the processing is complete, and the response is prepared to be returned.
-
before_finalize: This hook point is called right before the CherryPy has formatted the final response object and after the page handler has been processed.
-
after_error_response: This hook point is called before the error response is finalized and after the error response is set.
-
before_error_response: As the name depicts, this hook point is called before the error response is set.
-
on_end_request: This is the final hook point called. It is called after all the responses have been set and finalized, and there is nothing more to do.
For instance, if we wanted to declare a before_handler hook point the code snippet would look something like this,
def __init__(self):
# declaring a beforehandler hook
cherrypy.Tool.__init__(self, 'before_handler', self.load, priority=10)
We can also edit the priority of the function. In this case, we have added a priority of ten which is the highest priority. Priority ranges from zero to ten, zero being the lowest priority and ten being the highest priority.
Now let's discuss some frequently asked questions associated with Hook Points in cherrypy.




