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.
pip install pecanVerified import paths — ran on the pinned version, not inferred.
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`.
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.
Be prepared to integrate these functionalities manually using third-party libraries. Pecan's documentation includes tutorials for integrating these.
Ensure your environment has `webob` installed at version `1.8` or newer when using Pecan 1.4.0 or later.
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.
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)`.