minarrow-pyo3
PyO3 bindings for MinArrow - zero-copy Arrow interop with Python via PyArrow.
Overview
This crate provides transparent wrapper types that enable seamless conversion between MinArrow's Rust types and PyArrow's Python types using the Arrow C Data Interface.
Type Mappings
| MinArrow | PyArrow | Wrapper Type |
|---|---|---|
Array |
pa.Array |
PyArray |
Table |
pa.RecordBatch |
PyRecordBatch |
Installation
Prerequisites
- Python 3.9+
- PyArrow 14+
- Rust nightly (for MinArrow)
- maturin
Building
For a release build:
Usage
Rust Side
Create PyO3 functions that accept and return PyArrow types:
use ;
use ;
use *;
Python Side
# Array roundtrip
=
=
# PyArrow array
# RecordBatch roundtrip
=
=
# PyArrow RecordBatch
Features
datetime- Enable datetime/temporal type supportextended_numeric_types- Enable i8, i16, u8, u16 typesextended_categorical- Enable Categorical8, Categorical16, Categorical64
Testing
Python Tests
Run the comprehensive Python test suite:
Rust Tests
Run the Rust roundtrip tests. These require special setup because PyO3's extension-module
feature (default) doesn't link against libpython.
# 1. Find which Python library the binary links against:
|
# 2. Set PYTHONHOME to that Python's prefix:
# e.g., if it links to /usr/local/lib/libpython3.12.so, use PYTHONHOME=/usr/local
# You can verify with: /usr/local/bin/python3.12 -c "import sys; print(sys.prefix)"
# 3. Run the tests:
PYTHONHOME=/usr/local
The --no-default-features disables extension-module, allowing the binary to link
against libpython for standalone execution.
Architecture
The bindings use the Arrow C Data Interface for zero-copy data transfer:
- Rust -> Python: MinArrow's
export_to_c()exports to Arrow C format, PyArrow's_import_from_c()imports it - Python -> Rust: PyArrow's
_export_to_c()exports, MinArrow'simport_from_c()imports
Memory is managed through reference counting - the Arrow release callbacks ensure proper cleanup when either side releases the data.
License
MIT