# Pyramid — Versatile Python Web Framework for Any Scale > Pyramid is a mature, general-purpose Python web framework that scales from single-file applications to large enterprise systems, offering traversal and URL dispatch routing, pluggable authentication, and deep extensibility. ## Install Save in your project root: # Pyramid — Versatile Python Web Framework for Any Scale ## Quick Use ```bash pip install pyramid ``` ```python from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello(request): return Response("Hello, Pyramid!") if __name__ == "__main__": with Configurator() as config: config.add_route("hello", "/") config.add_view(hello, route_name="hello") app = config.make_wsgi_app() server = make_server("0.0.0.0", 6543, app) server.serve_forever() ``` ## Introduction Pyramid is a Python web framework from the Pylons Project that is designed to start small and grow with your application. It provides two routing mechanisms (URL dispatch and traversal), a flexible security system, and an extension architecture that allows developers to choose their own ORM, template engine, and session backend. ## What Pyramid Does - Routes requests via URL dispatch (regex patterns) or traversal (resource trees) - Provides a pluggable authentication and authorization policy system - Supports view configuration via decorators, imperative calls, or ZCML - Offers asset specifications for locating templates, static files, and resources - Includes a scaffolding system (cookiecutter templates) for project bootstrapping ## Architecture Overview Pyramid is a WSGI framework built around a Configurator that registers routes, views, and policies. At request time, the router matches a URL to a route or traverses a resource tree, selects the appropriate view callable, applies security predicates, and returns a Response. The framework uses a component architecture (based on Zope interfaces) for extensibility, allowing add-ons to hook into nearly any processing stage. ## Self-Hosting & Configuration - Requires Python 3.8 or later - Install with `pip install pyramid` or from a cookiecutter template - Configuration is done in Python via the Configurator object - Deploy with any WSGI server: Gunicorn, uWSGI, or Waitress (included) - Use `pserve development.ini` during development for auto-reload ## Key Features - Dual routing system: URL dispatch for REST APIs, traversal for content-heavy apps - Security policies are pluggable and decoupled from views - Extensible via add-ons that hook into the configurator without monkey-patching - First-class support for internationalization and localization - Comprehensive test harness with `pyramid.testing` for unit and functional tests ## Comparison with Similar Tools - **Django** — opinionated full-stack with built-in ORM; Pyramid is choose-your-own-components - **Flask** — micro framework for simple apps; Pyramid scales better to complex architectures - **FastAPI** — async-first API framework; Pyramid is WSGI-based with deeper extensibility - **Tornado** — async server with its own event loop; Pyramid runs on standard WSGI servers - **web2py** — batteries-included with admin UI; Pyramid favors explicit configuration ## FAQ **Q: When should I choose Pyramid over Django?** A: Choose Pyramid when you need flexibility in component selection (ORM, template engine) or when your routing needs go beyond simple URL patterns (traversal). **Q: Does Pyramid support async views?** A: Pyramid 2.0 added initial async view support. For fully async applications, consider pairing with an ASGI adapter or using a dedicated async framework. **Q: What is traversal routing?** A: Traversal walks a tree of resource objects using URL path segments as keys. It is useful for CMS-like applications where URL structure mirrors a content hierarchy. **Q: Is Pyramid still actively maintained?** A: Yes. The Pylons Project maintains Pyramid with regular releases and security patches. ## Sources - https://github.com/Pylons/pyramid - https://trypyramid.com/ --- Source: https://tokrepo.com/en/workflows/asset-7b4e6f2d Author: AI Open Source