The Pyramid Web Framework¶
Pyramid is a small, fast, down-to-earth Python web framework. It is developed as part of the Pylons Project. It is licensed under a BSD-like license.
Here is one of the simplest Pyramid applications you can make:
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)
server.serve_forever()
After you install Pyramid and run this application, when you visit
http://localhost:6543/ in a browser, you will see the text
Hello World!
See Creating Your First Pyramid Application for a full explanation of how
this application works.
Getting Started¶
If you are new to Pyramid, we have a few resources that can help you get up to speed right away.
Quick Tour of Pyramid gives an overview of the major features in Pyramid, covering a little about a lot.
Like learning by example? Visit the official Tutorials as well as the community-contributed Pyramid Tutorials and Pyramid Community Cookbook.
For help getting Pyramid set up, try Installing Pyramid.
Need help? See Support and Development.
Tutorials¶
Official tutorials provide a quick overview of Pyramid's features in more depth than the Quick Tour and with working code, explain how to use Pyramid to build various types of applications, and how to deploy Pyramid applications to various platforms.
Support and Development¶
The Pyramid website is the main entry point to Pyramid web framework resources for support and development information.
To report bugs, use the issue tracker.
If you've got questions that aren't answered by this documentation, contact the Pylons-discuss maillist or join the #pyramid IRC channel.
Browse and check out tagged and trunk versions of Pyramid via the
Pyramid GitHub repository. To check out
the trunk via git
, use either command:
# If you have SSH keys configured on GitHub:
git clone git@github.com:Pylons/pyramid.git
# Otherwise, HTTPS will work, using your GitHub login:
git clone https://github.com/Pylons/pyramid.git
To find out how to become a contributor to Pyramid, please see How to Contribute Source Code and Documentation.
Narrative Documentation¶
Narrative documentation in chapter form explaining how to use Pyramid.
- Pyramid Introduction
- Installing Pyramid
- Creating Your First Pyramid Application
- Application Configuration
- Creating a Pyramid Project
- Pyramid cookiecutters
- Creating the Project
- Installing your Newly Created Project for Development
- Running the Tests for Your Application
- Running the Project Application
- Viewing the Application
- The Project Structure
- The
myproject
Project - The
myproject
Package - Modifying Package Structure
- Using the Interactive Shell
- What Is This
pserve
Thing - Using an Alternate WSGI Server
- Automatically Reloading Your Code
- Startup
- Request Processing
- URL Dispatch
- High-Level Operational Overview
- Route Configuration
- Route Matching
- Routing Examples
- Matching the Root URL
- Generating Route URLs
- Static Routes
- External Routes
- Redirecting to Slash-Appended Routes
- Debugging Route Matching
- Using a Route Prefix to Compose Applications
- Custom Route Predicates
- Route Factories
- Using Pyramid Security with URL Dispatch
- Route View Callable Registration and Lookup Details
- References
- Views
- View Callables
- Defining a View Callable as a Function
- Defining a View Callable as a Class
- View Callable Responses
- Using Special Exceptions in View Callables
- Custom Exception Views
- Using a View Callable to do an HTTP Redirect
- Handling Form Submissions in View Callables (Unicode and Character Set Issues)
- Alternate View Callable Argument/Calling Conventions
- Passing Configuration Variables to a View
- Pylons-1.0-Style "Controller" Dispatch
- Renderers
- Templates
- View Configuration
- Static Assets
- Request and Response Objects
- Sessions
- Using Events
- Environment Variables and
.ini
File Settings- Reloading Templates
- Reloading Assets
- Debugging Authorization
- Debugging Not Found Errors
- Debugging Route Matching
- Preventing HTTP Caching
- Preventing Cache Busting
- Debugging All
- Reloading All
- Default Locale Name
- Including Packages
- Explicit Tween Configuration
- Examples
- Understanding the Distinction Between
reload_templates
andreload_assets
- Adding a Custom Setting
- Logging
- PasteDeploy Configuration Files
- Command-Line Pyramid
- Running p-scripts
pviews
: Displaying Matching Views for a Given URLpshell
: The Interactive Shellproutes
: Displaying All Application Routesptweens
: Displaying "Tweens"prequest
: Invoking a Requestpdistreport
: Showing All Installed Distributions and Their Versions- Writing a Script
- Making Your Script into a Console Script
- Internationalization and Localization
- Creating a Translation String
- Working with
gettext
Translation Files - Using a Localizer
- Obtaining the Locale Name for a Request
- Performing Date Formatting and Currency Formatting
- Chameleon Template Support for Translation Strings
- Mako Pyramid i18n Support
- Jinja2 Pyramid i18n Support
- Localization-Related Deployment Settings
- "Detecting" Available Languages
- Activating Translation
- Locale Negotiators
- Virtual Hosting
- Unit, Integration, and Functional Testing
- Resources
- Defining a Resource Tree
- Location-Aware Resources
- Generating the URL of a Resource
- Generating the Path To a Resource
- Finding a Resource by Path
- Obtaining the Lineage of a Resource
- Determining if a Resource is in the Lineage of Another Resource
- Finding the Root Resource
- Resources Which Implement Interfaces
- Finding a Resource with a Class or Interface in Lineage
- Pyramid API Functions That Act Against Resources
- Hello Traversal World
- Much Ado About Traversal
- Traversal
- Security
- Enabling an Authorization Policy
- Protecting Views with Permissions
- Assigning ACLs to Your Resource Objects
- Elements of an ACL
- Special Principal Names
- Special Permissions
- Special ACEs
- ACL Inheritance and Location-Awareness
- Changing the Forbidden View
- Debugging View Authorization Failures
- Debugging Imperative Authorization Failures
- Extending Default Authentication Policies
- Creating Your Own Authentication Policy
- Creating Your Own Authorization Policy
- Admonishment Against Secret-Sharing
- Preventing Cross-Site Request Forgery Attacks
- Combining Traversal and URL Dispatch
- Invoking a Subrequest
- Using Hooks
- Changing the Not Found View
- Changing the Forbidden View
- Changing the Request Factory
- Adding Methods or Properties to a Request Object
- Changing the Response Factory
- Using the Before Render Event
- Using Response Callbacks
- Using Finished Callbacks
- Changing the Traverser
- Changing How
pyramid.request.Request.resource_url()
Generates a URL - Changing How Pyramid Treats View Responses
- Using a View Mapper
- Registering Configuration Decorators
- Registering Tweens
- Adding a Third Party View, Route, or Subscriber Predicate
- View Derivers
- Pyramid Configuration Introspection
- Extending an Existing Pyramid Application
- Advanced Configuration
- Extending Pyramid Configuration
- Pyramid cookiecutters
- Creating Pyramid Scaffolds
- Upgrading Pyramid
- Thread Locals
- Using the Zope Component Architecture in Pyramid
API Documentation¶
Comprehensive reference material for every public API exposed by Pyramid:
- API Documentation
pyramid.authentication
pyramid.authorization
pyramid.compat
pyramid.config
pyramid.csrf
pyramid.decorator
pyramid.events
pyramid.exceptions
pyramid.httpexceptions
pyramid.i18n
pyramid.interfaces
pyramid.location
pyramid.paster
pyramid.path
pyramid.registry
pyramid.renderers
pyramid.request
pyramid.response
pyramid.scaffolds
pyramid.scripting
pyramid.security
pyramid.session
pyramid.settings
pyramid.static
pyramid.testing
pyramid.threadlocal
pyramid.traversal
pyramid.tweens
pyramid.url
pyramid.view
pyramid.viewderivers
pyramid.wsgi
p*
Scripts Documentation¶
p*
scripts included with Pyramid.
Change History¶
- What's New in Pyramid 1.10
- What's New in Pyramid 1.9
- What's New in Pyramid 1.8
- What's New in Pyramid 1.7
- What's New in Pyramid 1.6
- What's New in Pyramid 1.5
- What's New in Pyramid 1.4
- What's New in Pyramid 1.3
- What's New in Pyramid 1.2
- What's New in Pyramid 1.1
- What's New in Pyramid 1.0
- Pyramid Change History
repoze.bfg
Change History (previous name for Pyramid)