The Pyramid Web Framework¶
Pyramid is a small, fast, down-to-earth Python web framework. It isdeveloped as part of thePylons Project.It is licensed under aBSD-like license.
Here is one of the simplestPyramid applications you can make:
fromwsgiref.simple_serverimportmake_serverfrompyramid.configimportConfiguratorfrompyramid.responseimportResponsedefhello_world(request):returnResponse('Hello World!')if__name__=='__main__':withConfigurator()asconfig: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 installPyramid and run this application, when you visithttp://localhost:6543/ in a browser, you will see the textHelloWorld!
SeeCreating Your First Pyramid Application for a full explanation of howthis application works.
Getting Started¶
If you are new to Pyramid, we have a few resources that can help you get up tospeed 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 officialTutorials as well asthe community-contributedPyramid Tutorials andPyramid Community Cookbook.
For help getting Pyramid set up, tryInstalling Pyramid.
Need help? SeeSupport and Development.
Tutorials¶
Official tutorials provide a quick overview ofPyramid's features in more depth than the Quick Tour and with working code, explain how to usePyramid to build various types of applications, and how to deployPyramid applications to various platforms.
Support and Development¶
ThePyramid website is the mainentry point toPyramid web framework resources for support anddevelopment information.
To report bugs, use theissue tracker.
If you've got questions that aren't answered by this documentation, contact thePylons-discuss maillist or join the#pyramid IRC channel.
Browse and check out tagged and trunk versions ofPyramid via thePyramid GitHub repository. To check outthe trunk viagit
, 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 toPyramid, please seeHow to Contribute Source Code and Documentation.
Narrative Documentation¶
Narrative documentation in chapter form explaining how to usePyramid.
- Pyramid Introduction
- InstallingPyramid
- Creating Your FirstPyramid Application
- Application Configuration
- Creating aPyramid 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
- UsingPyramid 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
- Writing a Security Policy
- Protecting Views with Permissions
- Implementing ACL Authorization
- 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
- 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 Custom View, Route, or Subscriber Predicate
- View Derivers
- Pyramid Configuration Introspection
- Extending an ExistingPyramid Application
- Advanced Configuration
- Extending Pyramid Configuration
- Pyramid cookiecutters
- Upgrading Pyramid
- Thread Locals
- Using the Zope Component Architecture inPyramid
API Documentation¶
Comprehensive reference material for every public API exposed byPyramid:
- API Documentation
pyramid.authentication
pyramid.authorization
- Constants
- Return Values
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.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 withPyramid.
Change History¶
- What's New in Pyramid 2.0
- 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)