Pyramid Web Framework
Pyramid is a minimalistic, flexible, and open-source Python web framework that prioritizes simplicity, scalability, and ease of use. It is part of the Pylons Project and is currently at version 2.1, with releases typically following a maintenance and deprecation policy where deprecated features are kept for at least three minor releases before removal. [1, 2, 12, 16]
Warnings
- breaking Pyramid versions 2.0 and later are Python 3 only. Python 2.x is no longer supported. [3, 14]
- breaking The authentication and authorization policies from Pyramid 1.x have been merged into a single security policy in Pyramid 2.0. The `ISession` interface for sessions now only supports JSON-serializable data types for security reasons, which is a backward-incompatible change. [14, 15]
- deprecated Several ACL-related constants previously imported from `pyramid.security` are now deprecated. [15]
- gotcha Pyramid's configuration system, especially with `.ini` files and `pserve`, is powerful but can be a point of confusion for new users. Incorrect configuration paths or settings can lead to application startup issues. [10, 13]
Install
-
pip install "pyramid==2.1" -
pip install pyramid
Imports
- Configurator
from pyramid.config import Configurator
- Response
from pyramid.response import Response
- make_server
from wsgiref.simple_server import make_server
- view_config
from pyramid.view import view_config
Quickstart
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()
server = make_server('0.0.0.0', 6543, app)
print('Serving on http://0.0.0.0:6543')
server.serve_forever()