Skip to content

Cross Plugin Communication

Asterios Raptis edited this page May 21, 2026 · 1 revision

Cross-Plugin Communication

PluginForge plugins run in the same Python process and can interact through three patterns, listed in order of preference.

1. Hookspecs (recommended for most cases)

The host application defines hookspecs; plugins implement them via @hookimpl. The host dispatches hooks at the right lifecycle moment. Plugins don't need to know about each other. This is pluggy's native mechanism and PluginForge's primary extension model.

When to use: plugin provides a capability the host orchestrates (export formats, content transforms, AI completions).

Example: a host defines an export_execute hookspec. Any plugin can implement it. The host's export router dispatches it. A new plugin adding a PDF export format just implements the hook, no imports from other plugins needed.

Limitation: hooks are one-shot dispatch calls. If a plugin needs a multi-method service object from another plugin, hooks are too coarse.

See Hooks for hookspec definition, @hookimpl registration, and dispatch details.

2. Direct Python imports (acceptable for tightly coupled plugins)

Plugin B imports from Plugin A's package directly. Simple, explicit, no framework abstraction needed.

When to use: two plugins are developed together, share a release cycle, and the dependency is stable. Typically first-party plugins in a monorepo.

Constraints:

  • Declare depends_on = ["plugin-a"] so PluginForge activates A before B.
  • Handle ImportError gracefully if the dependency might not be installed (optional cross-plugin feature).
  • This pattern does NOT work safely for external/third-party plugins because the imported plugin's internal API is not guaranteed stable.

3. Service-Registry (future, not yet in PluginForge)

For cases where plugins need typed service objects from other plugins without direct imports. Not yet implemented in PluginForge. If your use case requires this, use hookspecs or direct imports for now.

Recommendation

The recommended path for most applications: define hookspecs in the host for every cross-cutting concern, and let plugins implement them. depends_on handles activation ordering. Direct imports are acceptable for first-party plugins under your control.

Clone this wiki locally