Hackernoon logoCherrypy Introduction: Simple Python Library for Quick Application Development by@vaibhavtyagi

Cherrypy Introduction: Simple Python Library for Quick Application Development

For day to day work in dev-ops or for testing team , we need to put stub in between some application to fill the gap for the application which are not present on local testing lab , for that we need to put some stub so that it can mimic like actual application .

We will discuss one tool here which eventually make tester and developer life very easy , The cherrypy library of python.

I will write simplest code example to create HTTP server , which takes json payload in POST request and also send the json response in reply.

Sample request

Payload  '{"tid": "11000098777","deviceid": "9000002020020202"}'

Response from server


Sample code for above requirement in python

Instillation steps

For installing cherrypy you need to use pip utility and can install cherrypy

pip install cherrypy


import cherrypy
import os.path
import configparser
import json

class Server(object):
  def __init__(self):
        with open('./response.json') as f:
            self.response_json_object = json.load(f)

    def context(self):
        return self.response_json_object

cherrypy.quickstart(Server(),'/', config=configfile)
  • Above program is using one config file named server.conf
  • Also it is reading one json file which will be send as json response for the incoming request.


server.socket_host = ''
server.socket_port = 9990
tools.staticdir.on = False
tools.staticdir.dir =
log.access_file = "./logs/access1.log"
log.error_file = "./logs/error1.log"
log.screen = False
tools.sessions.on = True



On Linux terminal you can use below command to run the program

Start the application

paython Server.py &

Test the application

curl -i -X POST -H "Content-Type:application/json" '' --data '{"tid": "11000098777","deviceid": "9000002020020202"}'


Join Hacker Noon

Create your free account to unlock your custom reading experience.