How to start a server with python framework Pyramid
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
No comments yet. Be the first to comment.
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

This article shows how to start a simple server with Pyramid.
First, you need the following programs available on your system:
It all should be provided with a python package in your operating system.
To avoid polluting the global scope with package versions, we can start & use the virtual environment:
$ python3 -m venv .venv
When successful, this command creates .venv folder & produces no output.
To switch to the virtual env:
$ source .venv/bin/activate
(.venv) $
The current console will use .venv as the location for packages managed by pip.
(.venv) $ pip install pyramid
Collecting pyramid
Downloading pyramid-2.0-py3-none-any.whl (246 kB)
|████████████████████████████████| 246 kB 2.4 MB/s
Collecting hupper>=1.5
Using cached hupper-1.10.3-py2.py3-none-any.whl (26 kB)
Requirement already satisfied: setuptools in ./.venv/lib/python3.8/site-packages (from pyramid) (44.0.0)
Collecting webob>=1.8.3
Using cached WebOb-1.8.7-py2.py3-none-any.whl (114 kB)
Collecting zope.interface>=3.8.0
Using cached zope.interface-5.4.0-cp38-cp38-manylinux2010_x86_64.whl (259 kB)
Collecting plaster-pastedeploy
Using cached plaster_pastedeploy-0.7-py2.py3-none-any.whl (7.8 kB)
Collecting translationstring>=0.4
Using cached translationstring-1.4-py2.py3-none-any.whl (15 kB)
Collecting venusian>=1.0
Using cached venusian-3.0.0-py3-none-any.whl (13 kB)
Collecting plaster
Using cached plaster-1.0-py2.py3-none-any.whl (14 kB)
Collecting zope.deprecation>=3.5.0
Using cached zope.deprecation-4.4.0-py2.py3-none-any.whl (10 kB)
Collecting PasteDeploy>=2.0
Using cached PasteDeploy-2.1.1-py2.py3-none-any.whl (17 kB)
Installing collected packages: hupper, webob, zope.interface, PasteDeploy, plaster, plaster-pastedeploy, translationstring, venusian, zope.deprecation, pyramid
Successfully installed PasteDeploy-2.1.1 hupper-1.10.3 plaster-1.0 plaster-pastedeploy-0.7 pyramid-2.0 translationstring-1.4 venusian-3.0.0 webob-1.8.7 zope.deprecation-4.4.0 zope.int
erface-5.4.0
I use a slightly modified example from the documentation. server.py:
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__':
HOST = '0.0.0.0'
PORT = 6543
with Configurator() as config:
config.add_route('hello', '/')
config.add_view(hello_world, route_name='hello')
app = config.make_wsgi_app()
server = make_server(HOST, PORT, app)
print(f'Starting server at {HOST}:{PORT}')
server.serve_forever()
I moved HOST & PORT into variables and logged them to the console. Otherwise, the server was quietly working without notifying the user about its presence.
(.venv) $ python3 server.py
Starting server at 0.0.0.0:6543
The server works as expected:

We have seen how to start a simple Pyramid server.