reasonable (Python bindings)
Python bindings for Reasonable — a reasonably fast OWL 2 RL reasoner implemented in Rust. This package exposes a small, typed API over rdflib terms to run materialization on RDF graphs or files.
Quick Usage
Load from files (Turtle/N3) and materialize inferred triples:
=
= # list[tuple[rdflib.term.Node, Node, Node]]
Reason directly over an rdflib Graph:
=
=
=
# Optionally collect into a new Graph
=
Install
- Runtime dependency:
rdflib - If you have a prebuilt wheel:
pip install dist/reasonable-*.whl - Build from source (see below) if no wheel is available for your platform.
Developer Install (from source)
Using uv (recommended for local dev):
# Install project dependencies (including dev tools) into a managed venv
# Build and develop-install the extension module
# Sanity check
Without uv (system/venv):
&&
API Reference (minimal)
reasonable.PyReasoner()load_file(path: str) -> None- Load triples from a Turtle or N3 file. Raises
OSErroron missing/invalid paths.
- Load triples from a Turtle or N3 file. Raises
from_graph(graph_or_iterable) -> None- Accepts an rdflib
Graphor any iterable of 3-tuples convertible to rdflib-like nodes.
- Accepts an rdflib
reason() -> list[tuple[Node, Node, Node]]- Runs OWL 2 RL materialization and returns all known triples as rdflib nodes.
Building Wheels
Build release wheels into dist/:
Install the built wheel:
Requirements
- Python 3.9+ (ABI3, built with
pyo3/abi3-py39) - Rust toolchain (
rustup,cargo) for local builds maturinfor building wheelsrdflib(runtime dependency)
Testing
Run the Python test suite (uses pytest and rdflib):
Alternatively, with a local venv:
Compatibility Notes
- Python: 3.9+ is required due to the ABI3 setting in the Rust crate (
abi3-py39). - Platforms: macOS, Linux, and Windows are supported by PyO3/maturin; building from source requires a Rust toolchain.
Troubleshooting
ModuleNotFoundError: No module named 'reasonable':- Ensure you ran
maturin developin the same environment you’re importing from.
- Ensure you ran
- Build/link errors on macOS (Xcode/SDK):
- Install Command Line Tools:
xcode-select --install.
- Install Command Line Tools:
OSErrorwhen callingload_file(...):- Check the path and file format (Turtle/N3). Use absolute paths when in doubt.
Contributing (Python bindings)
- Keep tests under
python/tests/minimal and representative. Prefer inputs fromexample_models/. - Format/lint Python with standard tooling; Rust code follows
cargo fmt/cargo clippy. - For broader project info (CLI, library, benchmarks), see the repository root
README.md.