Pyramid is a web framework to build web applications based on Python. It's easier to use and to handle HTTP requests. You can install pyramid by typing this command:
$ pip install "pyramid==1.9.1"
It will install pyramid version 1.9.1. You can change it.
For testing, we'll build a simple web application to handle the / request. Use the following code:
from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello_world(request): return Response('Hello World!') if __name__ == '__main__': with Configurator() as config: config.add_route('hello', '/') config.add_view(hello_world, route_name='hello') app = config.make_wsgi_app() print('server is running') server = make_server('0.0.0.0', 8099, app) server.serve_forever()
Save this program to a file called ch04_pyramid.py.
Now you can run it. Type this command on the terminal.
$ python ch04_pyramid.py
The program will run on port 8099. Open a browser and navigate to http://localhost:8099. You should get a response saying Hello World! in the browser:
On the terminal side, you can see the running program here: