Skip to main content

Crate backfire_kernel

Crate backfire_kernel 

Source
Expand description

Python-callable wrappers around the Rust Backfire Kernel.

Exposes RustSafetyKernel, RustStreamingKernel, RustCoherenceScorer, and supporting types to Python via PyO3.

This is a facade: one binding submodule per subsystem, each with a register hook called from the #[pymodule] entry point below, so the flat backfire_kernel.* Python surface is unchanged.

§FFI Safety

  • GIL acquired via Python::attach before every Python callback.
  • Python exceptions → safe Rust defaults (0.0 for scores, None for strings).
  • No borrowed references escape the GIL lock scope.
  • All config validated before storage (BackfireConfig::validate()).

Install: cd backfire-kernel && pip install -e crates/backfire-ffi (requires maturin).

Usage from Python:

from backfire_kernel import RustSafetyKernel, RustStreamingKernel

kernel = RustSafetyKernel(hard_limit=0.5)
result = kernel.stream_output(["Hello ", "world"], lambda t: 0.8)