Pyramid Framework - Core Concepts



The Pyramid framework is based on below core concepts −

  • Zope (extensibility, traversal, declarative security) − Pyramid is loosely based on Zope in terms of extensibility, the concept of traversal and the declarative security.

  • Pylons (URL dispatch, non-opinionated view of persistence, templating, etc.) − Another area from where pyramid draws its concept is the pylons project. Pylons have that concept of routes, that calls the URL dispatch inside the pyramid framework and they also have the non-opinionated view of persistence layer or templating.

  • Django (View, level of documentation) − Pyramid also gets hint from Django. The way we take our view, routed our URL and the level of documentation is very Django way.

The following are the features of the Pyramid framework −

  • It is the fastest known Python web framework.

  • It supports small and large projects (why rewrite when you outgrow your small framework).

  • It supports single file webapps like microframeworks.

  • It has built-in sessions.

  • It supports events similar to Plone/Zope.

  • It provides Transaction Management (if already have noticed that we have used Zope before).

Configuration

Configuration is the settings that influence the operation of an application. There are two ways to configure a pyramid application: imperative configuration and declarative configuration.

Pyramid configuration supports −

  • Imperative configuration or even the overriding of the decorator-based configs

  • Configuration conflict detection (including more local vs. less local determination)

  • Configuration Extensibility (included from multiple apps)

  • Flexible Authentication and Authorization Policies

  • Programmatic Introspection of Configuration (view current state of routes to generate nav)

URL generation

In pyramid, we can generate URLs for routes, resources and static assets. It is easy and flexible to work with URL generation APIs. By generating URLs through pyramids various APIs, users can change the configuration arbitrarily without much worry of breaking a link with any of your web pages.

So in short, URL in pyramid −

  • supports URL generation to allow changes to app that wont break links.

  • generates URLs to static resources that live either inside or outside the application.

  • supports Routes and Traversal.

Views

One of the primary jobs of pyramid is to find and invoke a view callable when a request reaches your application. View callables are bits of code which do something interesting in response to a request made in your application.

When you map your views onto your URL dispatch or python code, there can be any kind of call. Views can be a function declaration or an instance, it can be used as a view in the pyramid.

Some important points about Views are given below −

  • Views are generated from any callable.

  • Renderer based views can simply return dictionaries (not required to return a webby style object).

  • Support multiple views per route (GET vs. POST vs. HTTP Header check, etc.).

  • View response adapters (when you want to specify how view returns values should be handled vs. response objects).

Extensibility

Pyramid is designed with extensibility in mind. So if a pyramid developer is keeping in mind certain constraints while building an application, a third party should be able to change the applications behaviour without needing to modify its source code. The behaviour of a pyramid application that obeys certain constraints can be overridden or extended without any modification. It is designed for flexible deployments to multiple environments (No Singletons). Pyramid has Tweens middleware support (WSGI middle ware, but runs in the context of Pyramid itself).

Advertisements