| Crates.io | medmodels-pyo3-interop |
| lib.rs | medmodels-pyo3-interop |
| version | 0.4.9 |
| created_at | 2026-01-06 15:41:25.40933+00 |
| updated_at | 2026-01-23 21:43:09.300457+00 |
| description | Limebit MedModels Crate |
| homepage | |
| repository | https://github.com/limebit/medmodels |
| max_upload_size | |
| id | 2026105 |
| size | 99,431 |
Interoperability layer for passing MedModels types between independent PyO3 extension modules.
PyO3's #[pyclass] stores type objects in static storage, meaning each compiled extension module gets its own copy. When two separate PyO3 extensions try to share a type like MedRecord, Python sees them as distinct types, breaking compatibility (PyO3#1444).
This crate provides a workaround by serializing MedRecord to bytes (via bincode) when crossing extension boundaries, allowing external Rust-based Python extensions to accept and return MedRecord objects from the main medmodels package.
PyMedRecord - A wrapper around MedRecord implementing PyO3's FromPyObject and IntoPyObject traits via binary serializationPyNodeIndex, PyEdgeIndex, PyGroup, PyAttributes, etc.)use medmodels_pyo3_interop::PyMedRecord;
use pyo3::prelude::*;
#[pyfunction]
fn process_medrecord(record: PyMedRecord) -> PyResult<PyMedRecord> {
// Access the inner MedRecord
let inner = record.0;
// Process and return
Ok(inner.into())
}