Skip to content

[FEATURE]: Python bindings (PyO3) #19

@terylt

Description

@terylt

Epic: CPEX Rust Core (#12)

Summary

Create cpex-python crate providing PyO3 bindings so Python code can call the Rust PluginManager. This is the "Python → Rust" direction — Python hosts (like ContextForge gateway) use the Rust core for execution.

Motivation

The ContextForge gateway is written in Python. PyO3 bindings let it use the Rust PluginManager as a drop-in replacement, getting compile-time invariant enforcement and the typed hook system while keeping the existing Python integration code.

Scope

  • #[pymodule] exposing PyPluginManager
  • PyPluginManager — wraps cpex_core::PluginManager with Python-callable methods
  • invoke_hook(hook_name, payload, context, extensions) — Python calls, Rust executes
  • PyO3-wrapped Rust types for payloads and extensions — Python accesses attributes, Rust controls access
  • Maturin build configuration (pyproject.tomlcpex._native module)
  • Type stubs (_native.pyi) for IDE support
  • cpex/__init__.py import switch — Rust backend if available, Python fallback otherwise

Acceptance Criteria

  • from cpex import PluginManager loads the Rust-backed manager when compiled
  • manager.invoke_hook() dispatches through the Rust 5-phase executor
  • Python plugins receive PyO3-wrapped payloads with typed attributes
  • Existing PluginConfig YAML format works without changes
  • Falls back to pure Python implementation if Rust module not compiled

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No fields configured for Task.

Projects

Status
In progress

Relationships

None yet

Development

No branches or pull requests

Issue actions