Using processors¶
Processors are middleware components that intercept and transform Griffe objects before they reach your templates. They allow you to add custom metadata, modify object properties, or enrich the data available to your templates.
What processors do¶
Processors run between the Griffe parsing phase and template rendering, giving you a chance to:
- Add computed metadata (complexity scores, category classifications)
- Transform or filter object properties
- Enrich context with external data
- Modify object structure or content
Flow: Python Code → Griffe Parser → Processors → Template Engine → Output
Basic usage¶
Enable processors in your frontmatter using the processors
section:
---
template: "python/default/module.md.jinja2"
griffe_target: "mypackage.utils"
processors:
enabled: ["complexity_analyser", "doc_linker"]
output:
- filename: "utils.md"
griffe_target: "mypackage.utils"
---
Configuration options¶
Enabled processors¶
Specify exactly which processors to run:
Disabled processors¶
Run all available processors except specific ones:
Processor configuration¶
Pass configuration to processors:
processors:
enabled: ["complexity_analyser"]
config:
complexity_threshold: 15
include_metrics: ["cyclomatic", "halstead"]
The configuration is available to processors via context["processor_config"]
.
Execution order¶
Processors run in priority order (lower numbers first):
- Priority 50: Early processors (pre-processing)
- Priority 100: Default processors (standard processing)
- Priority 150: Late processors (post-processing)
Multiple processors at the same priority level run in alphabetical order by name.
Available processors¶
List all available processors:
This shows:
- Processors: Middleware components for object transformation
- Filters: Template filters from the same plugins
- Bundles: Collections of processors, filters, and templates
Installing processors¶
Processors are distributed as Python packages with entry points:
# Example packages (aspirational - not yet available)
pip install griffonner-complexity-analyser
pip install griffonner-doc-linker
After installation, they’re automatically discovered by Griffonner.
Examples¶
Documentation linker¶
---
template: "python/default/module.md.jinja2"
griffe_target: "mypackage.core"
processors:
enabled: ["doc_linker"]
config:
base_url: "https://docs.example.com"
link_external: true
---
The processor adds doc_links
to your template context:
## Functions
{% for name, func in obj.functions.items() %}
### {{ func.name }}
{{ func.docstring.summary }}
{% if doc_links and doc_links[func.name] %}
[View full documentation]({{ doc_links[func.name] }})
{% endif %}
{% endfor %}
Complexity analyser¶
Adds complexity data to context:
## Functions
{% for name, func in obj.functions.items() %}
### {{ func.name }}
{% if complexity and complexity[func.name] %}
**Complexity**: {{ complexity[func.name].score }}
{% if complexity[func.name].score > 10 %}
⚠️ High complexity function
{% endif %}
{% endif %}
{% endfor %}
Troubleshooting¶
Processor not found¶
- Check the processor is installed:
pip list | grep griffonner
- List available processors:
griffonner plugins
- Check spelling in frontmatter
Processor failed¶
- Check processor documentation for required configuration
- Add missing config to frontmatter
processors.config
- Ensure config values are correct type (string, number, boolean)
No processors running¶
If no processors
section is in frontmatter, all available processors run by default. To disable all processors:
See also¶
- Managing plugins - Installing and discovering plugins
- Using filters - Custom template filters
- Plugin development - Creating your own processors