Pillars of Python: Pyramid Web framework

Built on the foundation of repoze.bfg, Pyramid is powerfully flexible but takes time to figure out

1 2 3 Page 2
Page 2 of 3

Pyramid: URLs to resources
Resources provide structure to an application, and in a very real sense, a Pyramid resource corresponds to the classic definition of that word: any entity that can be named and acted upon. Typically, a resource is either the representation of a persistent object (a collection of attributes), a container, or both. In processing an HTTP request's URI, the framework ultimately determines the context resource -- the one that will be used to process the request.

When you use the traversal URL mapping mechanism in Pyramid, resources act much like Zope 2's Zope objects. Pyramid parses the components of the URL, using them to describe a path beginning with the root resource and proceeding through resources issuing from the root. Because of this, Pyramid's creators often refer to the framework as supporting an RV (resource-view) architecture, rather than an MVC (model-view-controller) architecture.

When building Pyramid applications, you'll find yourself making heavy use of paster, a component of the Python Paste project. Paster is how one runs scripts that employ the paste module, which functions as a sort of glue layer between a WSGI-compliant Web server and a Web application.

Paste encapsulates a great deal of functionality. For example, paste provides code for authenticating user logins, validating WSGI compliance, and catching HTTP-related exceptions. Paste also provides a convenient way of executing Python scripts encapsulated as Python eggs -- a Python egg being an easily distributed Python application package, roughly analogous to the JAR file of the Java world.

While you can certainly create a Pyramid Web application from scratch, Pyramid comes with paster templates for quickly erecting the infrastructure for any of several Web application types, each type varying the sort of URL mapping used and the type of persistence mechanism employed. For example, one template builds a skeletal application that uses URL dispatch for URL-to-code mapping and SQLAlchemy as the back-end database system. Another builds a base application that uses traversal URL mapping and a ZODB (Zope Object Database) persistence engine.

1 2 3 Page 2
Page 2 of 3
InfoWorld Technology of the Year Awards 2023. Now open for entries!