Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save inklesspen/ddad12ab02e28186d83f to your computer and use it in GitHub Desktop.

Select an option

Save inklesspen/ddad12ab02e28186d83f to your computer and use it in GitHub Desktop.

Adapting Pyramid to Fit your Application

Description

There are many ways to build Pyramid apps, and knowing your options can help you make maintainable choices. Most people generate Pyramid apps using a scaffold and plug in one or two add-ons like pyramid_redis_session or pyramid_tm, but if you're interested in stepping beyond that, I'll show you some real-world examples of how we've adapted Pyramid to fit our apps.

Abstract

Pyramid offers an enormous amount of customization power; most apps only use a small portion of it. I'll show you how to identify the right way to customize the framework for your particular use case and how to use this power to make your app simpler and easier to understand.

View mappers

The standard Pyramid view is a function that accepts a request object and returns a response object, but many other patterns are possible. Pyramid uses an adapter called a view mapper to determine how to call your views. I'll show how we used view mappers in developing our APIs.

Modular configuration

The Pyramid Configurator class is a powerful tool for project organization. config.include() is commonly used to load add-ons, but I'll show you how to use it to keep logical concerns separated and make integration testing easier.

Events and callbacks

Pyramid's extensive lifecycle event system makes it easy to define behavior to happen at specific points in your app's execution. Learn how common add-ons like session implementations, pyramid_tm, and pyramid_mailer use these hooks and how you can use them yourself.

Tweens

Tweens wrap around the entire request/response; they can alter the request on the way in and the request on the way out. Much like WSGI middleware, they can achieve a variety of effects; I'll show a few simple recipes for things like enforcing a canonical hostname or managing static resources.

@pauleveritt

Copy link
Copy Markdown

Hi Jon, just wanted to check, are you submitting this talk to PyCon? I was thinking about submitting a Pyramid Add-On talk as well (as part of working on docs for add-ons) but I'd be happy to support your talk instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment