Simple Template Plugin

Beginner ~65 lines 15 minutes

DVP CMS is a truth distillation system for AI-generated content. Plugins are evidence suppliers—they verify facts, pull live data, and make content more trustworthy over time. Learn more →

← Back to Plugin Source Code
Plugin ID minimal-template
Version 1.0.0
Dependencies None (stdlib only)
Hooks ContentLifecycleHooks

This is the absolute minimum code needed for a working DVP CMS plugin. Use this as a starting point when you want the simplest possible plugin and plan to add complexity incrementally. For a fully-documented version with all patterns, see the Advanced Template.

Features

Single Hook Implements just dvp_before_content_create
No Configuration Works out of the box with no setup
No Dependencies Uses only Python standard library
Minimal Boilerplate Every line serves a purpose

Source Code

plugin.py
"""
Minimal Template Plugin for DVP CMS.

This is the ABSOLUTE MINIMUM code needed for a working DVP CMS plugin.
Use this as a starting point when you want the simplest possible plugin
and plan to add complexity incrementally.

For a fully-documented version with all patterns, see `_template-canonical/`.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from dvp_cms.kernel.plugin import Plugin
from dvp_cms.plugins.hookspec import ContentLifecycleHooks

if TYPE_CHECKING:
    from dvp_cms.kernel.event_bus import EventBus


class MinimalTemplatePlugin(Plugin, ContentLifecycleHooks):
    """Minimal plugin that adds a processed flag to content.

    This plugin does one thing: adds a 'processed_by' field to content
    before creation. It demonstrates the bare minimum needed for a
    working DVP CMS plugin.

    Configuration:
        None required.

    Example:
        >>> plugin = MinimalTemplatePlugin(event_bus)
        >>> await plugin.initialize({})
    """

    plugin_id = "minimal-template"
    plugin_version = "1.0.0"
    plugin_name = "Minimal Template"
    plugin_description = "The simplest possible DVP CMS plugin"
    plugin_author = "DVP CMS Team"
    plugin_capabilities = ["template"]

    def __init__(self, event_bus: EventBus) -> None:
        """Initialize the plugin."""
        super().__init__(event_bus)

    async def initialize(self, config: dict[str, object]) -> None:
        """Initialize with configuration (none required)."""
        self._logger.info("Minimal plugin initialized")

    async def shutdown(self) -> None:
        """Shut down the plugin."""
        await self.unsubscribe_all()
        self._logger.info("Minimal plugin shutdown")

    def dvp_before_content_create(
        self,
        content: dict[str, object],
        metadata: dict[str, object] | None = None,
    ) -> dict[str, object]:
        """Add a processed flag before content is created."""
        content["processed_by"] = self.plugin_id
        return content  # IMPORTANT: Always return content!

Usage

Example usage
from dvp_cms.kernel.event_bus import EventBus

# Initialize
event_bus = EventBus()
plugin = MinimalTemplatePlugin(event_bus)
await plugin.initialize({})

# The plugin automatically adds 'processed_by' to content
# when dvp_before_content_create is called by the kernel