{"id":9172,"library":"pecan","title":"Pecan Web Framework","description":"Pecan is a lean Python web framework (version 1.8.0) that uses an object-dispatching style for routing, inspired by CherryPy, TurboGears, and Pylons. It focuses on building HTTP-based applications with minimal dependencies, rather than being a 'full-stack' solution. The project maintains an active development status with regular releases addressing Python version compatibility and feature enhancements.","status":"active","version":"1.8.0","language":"en","source_language":"en","source_url":"http://github.com/pecan/pecan","tags":["web-framework","wsgi","rest","api","microframework"],"install":[{"cmd":"pip install pecan","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"WSGI request/response objects","package":"webob","optional":false},{"reason":"Default templating engine","package":"mako","optional":true},{"reason":"Logging utilities","package":"logutils","optional":false}],"imports":[{"note":"Decorator for controller methods to expose them via HTTP.","symbol":"expose","correct":"from pecan import expose"},{"note":"Function to create a Pecan WSGI application instance.","symbol":"make_app","correct":"from pecan import make_app"},{"note":"Global configuration object, accessible at runtime.","symbol":"conf","correct":"from pecan import conf"},{"note":"Base class for building RESTful controllers.","symbol":"RestController","correct":"from pecan.rest import RestController"}],"quickstart":{"code":"import os\nfrom wsgiref.simple_server import make_server\n\nfrom pecan import make_app, expose\n\n# app.py\nclass RootController(object):\n    @expose()\n    def index(self):\n        return 'Hello, Pecan!'\n\n    @expose('json')\n    def hello(self, name='World'):\n        return {'message': f'Hello, {name}!'}\n\n# config.py (simulated for quickstart)\nconfig = {\n    'root': 'app.RootController',\n    'template_path': 'templates',\n    'debug': True,\n    'app': {\n        'modules': ['app'],\n        'static_root': 'public'\n    },\n    'server': {\n        'port': os.environ.get('PORT', '8080'),\n        'host': '0.0.0.0'\n    }\n}\n\n# To run this, you would typically use `pecan serve config.py`\n# For a self-contained example:\nif __name__ == '__main__':\n    app = make_app(config['root'], **config['app'])\n    server = make_server(config['server']['host'], int(config['server']['port']), app)\n    print(f\"Serving Pecan on http://{config['server']['host']}:{config['server']['port']}\")\n    print(\"Visit / and /hello?name=Pecan\")\n    try:\n        server.serve_forever()\n    except KeyboardInterrupt:\n        pass","lang":"python","description":"This minimal example demonstrates how to define a `RootController` with two exposed methods (`index` and `hello`). The `make_app` function initializes the WSGI application using this controller and a simple configuration. To run a Pecan application, the standard method is `pecan serve config.py`, where `config.py` contains the application's configuration. The `if __name__ == '__main__':` block provides a way to run it directly for demonstration purposes without the `pecan` command-line tool, serving on `0.0.0.0:8080`."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer before upgrading to Pecan 1.8.0. If you need Python 3.8/3.9 support, use Pecan < 1.8.0.","message":"Pecan 1.8.0 (and subsequent versions) requires Python 3.10 or higher. Support for Python 3.8 and 3.9 has been removed.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Be prepared to integrate these functionalities manually using third-party libraries. Pecan's documentation includes tutorials for integrating these.","message":"Pecan is a lean framework and does not provide out-of-the-box support for common 'full-stack' features like sessions or database integrations.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your environment has `webob` installed at version `1.8` or newer when using Pecan 1.4.0 or later.","message":"Pecan 1.4.0 introduced a requirement for `webob >= 1.8`. Older versions of `webob` may cause unexpected behavior or errors.","severity":"breaking","affected_versions":">=1.4.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `use_context_locals = True` is set in your application configuration (`config['app']` dict or passed to `make_app`). Access `pecan.request` and `pecan.response` only within controller methods or hooks that are executed during a request's lifecycle.","cause":"Attempting to access `pecan.request` or `pecan.response` outside the scope of an active HTTP request (e.g., during application startup or in a background thread) or when `use_context_locals` is not enabled.","error":"AttributeError: `pecan.state` is not bound to a context-local context."},{"fix":"When using `pecan serve`, ensure you pass the path to a valid Python configuration file (e.g., `pecan serve config.py`). When using `make_app` directly, provide a dictionary for the `config` argument or pass root controller path and app config as keyword arguments, for example: `app = make_app('myapp.controllers.root.RootController', **app_config_dict)`.","cause":"The `pecan serve` command or `pecan.make_app` function was called without a valid configuration file path or a properly structured configuration dictionary.","error":"TypeError: setup_app() missing 1 required positional argument: 'config' (or similar configuration loading errors)"}]}