Skip to main content

Python bindings for the OntoLogos OWL reasoner — RDFS, OWL RL, and OWL EL classification

Project description

ontologos

PyPI Python Documentation License

Python bindings for OntoLogos — a Rust-native OWL reasoner for RDFS, OWL RL, OWL EL, OWL 2 DL, and SWRL on PyPI (1.1.1 published).

Install: pip install ontologos. Production profiles: rdfs, rl, el, auto, dl, swrl. Preview: alc, dl-preview. See Release status and Profile stability.

Load .owl / .ttl files or build ontologies in memory, run the same profile engines as the CLI, and export taxonomies to pandas or Polars. Powered by PyO3 and the stable Python ABI (abi3).

Full guide: ontologos.readthedocs.io — Python

Features

  • File or in-memoryReasoner(path=...) or Ontology / OntologyBuilder
  • Profiles"rdfs", "rl", "el", "auto", "dl", "swrl" on PyPI; "dl-preview", "alc" are preview
  • Classify — RDFS/RL materialization reports or EL taxonomy dicts
  • Explain — proof graph dicts with IRI-resolved conclusions (EL full traces)
  • Incremental — multi-pass add_subclass_of / remove_subclass_of with incremental=True
  • Export — optional subsumptions_to_pandas / subsumptions_to_polars

Install

Requires Python 3.10+.

pip install ontologos

Optional DataFrame helpers:

pip install 'ontologos[pandas]'
pip install 'ontologos[polars]'

Pre-built wheels are published for:

OS Architectures
Linux x86_64, aarch64 (manylinux)
macOS x86_64, aarch64
Windows x64, aarch64

One abi3 wheel per platform covers Python 3.10–3.13+. If no wheel matches, build from source (Rust + maturin).

Quick start

Download Pizza for EL examples (from a clone: ./benchmarks/scripts/download.sh at repo root):

# From repository clone only:
./benchmarks/scripts/download.sh

Classify an OWL file

import ontologos

# OWL EL taxonomy
reasoner = ontologos.Reasoner(path="pizza.owl", profile="el")
taxonomy = reasoner.classify()
print(taxonomy["subsumption_count"], taxonomy["subsumptions"][:3])

# RDFS materialization
reasoner = ontologos.Reasoner(path="ontology.owl", profile="rdfs")
report = reasoner.classify()
print(report["inferred_axioms"])

# Auto-detect profile (EL or RL)
reasoner = ontologos.Reasoner(path="ontology.owl", profile="auto")
result = reasoner.classify()

Build in memory

from ontologos import OntologyBuilder, Reasoner

builder = OntologyBuilder()
builder.add_class("http://example.org/A")
builder.add_class("http://example.org/B")
builder.subclass_of("http://example.org/A", "http://example.org/B")
ontology = builder.build()

reasoner = Reasoner(ontology=ontology, profile="el")
taxonomy = reasoner.classify()

Load from JSON dict instead of the builder (v2 or v3; writers on workspace 1.1.1 emit v3):

from ontologos import Ontology, Reasoner

ontology = Ontology.from_dict({
    "format_version": 2,
    "entities": [
        {"iri": "http://example.org/A", "kind": "Class"},
        {"iri": "http://example.org/B", "kind": "Class"},
    ],
    "axioms": [
        {"SubClassOf": {
            "subclass": "http://example.org/A",
            "superclass": "http://example.org/B",
        }}
    ],
})
reasoner = Reasoner(ontology=ontology, profile="el")
reasoner.classify()

Incremental edits

reasoner = Reasoner(ontology=ontology, profile="el", incremental=True)
reasoner.classify()

reasoner.add_subclass_of("http://example.org/B", "http://example.org/C")
reasoner.classify()  # re-classify with warm session

reasoner.remove_subclass_of("http://example.org/A", "http://example.org/B")
reasoner.classify()

Explain inferences

graph = reasoner.explain()
print(graph["node_count"])
for node in graph["nodes"][:5]:
    print(node["rule"], node.get("conclusion_sub"))
Profile Explain coverage
EL Full inference traces
RL / RDFS Asserted axioms seeded; inferred steps lack per-rule premises until upstream exposes traces
auto Routes like classify

Export to DataFrame

from ontologos import subsumptions_to_pandas

df = subsumptions_to_pandas(taxonomy)
# columns: subclass, superclass

API overview

Type / method Description
Reasoner(path=..., profile=..., incremental=False) Load OWL file and classify
Reasoner(ontology=..., ...) Classify in-memory ontology
reasoner.classify() Run engine; returns taxonomy or materialization dict
reasoner.explain() Proof graph dict (node_count, nodes, parse_meta)
reasoner.taxonomy Last EL taxonomy (after classify)
reasoner.parse_meta Parser warnings and axiom counts
reasoner.add_subclass_of / remove_subclass_of Incremental axiom edits
reasoner.add_axiom_json Add axiom via JSON object (v2/v3 shape)
Ontology.from_json / from_dict Load JSON snapshot (v2 or v3)
OntologyBuilder Fluent builder → build()
subsumptions_to_pandas / subsumptions_to_polars Optional taxonomy export

Invalid profiles and unsupported constructs raise RuntimeError with a message string.

Reasoner is not thread-safe — do not mutate from multiple threads.

Development

From a repository clone:

cd crates/ontologos-py
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install 'maturin>=1.7,<2.0' pytest '.[pandas]'
maturin develop --release
pytest tests/ -q

Pizza EL golden test (requires corpus):

./benchmarks/scripts/download.sh   # from repo root
pytest tests/test_pizza_golden.py -q

What OntoLogos is (and is not)

OntoLogos is an orchestration layer: profile detection, a unified ontology model, CLI, Python wheels, and security limits on top of in-house EL, ontologos-dl for OWL 2 DL, and reasonable for RL/RDFS. It maps a subset of OWL — validate on your corpus before production cutover.

For engine-only workflows, consider reasonable, whelk-rs, or horned-owl directly.

Links

Resource URL
Python guide readthedocs — Python
Getting started readthedocs
Migration v0.9 → v1.0 migration guide
Repository github.com/eddiethedean/ontologos
Rust crates crates.io — ontologos-core
Changelog CHANGELOG.md

License

Licensed under either of Apache-2.0 or MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ontologos-1.1.1.tar.gz (426.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ontologos-1.1.1-cp310-abi3-win_arm64.whl (2.4 MB view details)

Uploaded CPython 3.10+Windows ARM64

ontologos-1.1.1-cp310-abi3-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

ontologos-1.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

ontologos-1.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

ontologos-1.1.1-cp310-abi3-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

ontologos-1.1.1-cp310-abi3-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file ontologos-1.1.1.tar.gz.

File metadata

  • Download URL: ontologos-1.1.1.tar.gz
  • Upload date:
  • Size: 426.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for ontologos-1.1.1.tar.gz
Algorithm Hash digest
SHA256 bbf579514f15ad7a4f90c6d4fed1e0b3caebe2056daa0cccb61fe8c54cbe2bb3
MD5 17753334e656251db9ecdec2490261bd
BLAKE2b-256 ba22abac365e996b692e2c2fac2983ad32502ebf37da20c3d87d36142be9746c

See more details on using hashes here.

File details

Details for the file ontologos-1.1.1-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for ontologos-1.1.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 f1ec2b67a963280528776acd0509e220a41ef0542eb2234f819700e4289559ad
MD5 143fb6e8d24bc371ef568f84bdc79583
BLAKE2b-256 57aef874b3edf1f08854b61efbe09af52fc5e81632b11c9e007ab1d157c463d5

See more details on using hashes here.

File details

Details for the file ontologos-1.1.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for ontologos-1.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bbadefbfb71872472352abd446ea6aa0b1738fe82d718c46c3b7f21ce8015ca5
MD5 00a660b1c18ac284a56d1919047c724c
BLAKE2b-256 c4fdfc5fa55cb124104a0176f858d97b21f9717cd9a3d22ae9dd85ed413e30ac

See more details on using hashes here.

File details

Details for the file ontologos-1.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ontologos-1.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28a518a0820f2ce97453d74ab260b9707e48387ef69476a88f22db635fb1b423
MD5 cba929cb22c9b1b2d052288fa377c17b
BLAKE2b-256 0d608ec9386502feba266bafb00b23bfab7c34f8c9c789fc19a6dbc13a5d4104

See more details on using hashes here.

File details

Details for the file ontologos-1.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ontologos-1.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 745ed3f81744de0318785c93d80ec94a3853882a55e9632eead237e5f8a3a85c
MD5 344aabfd71d227805edc93b1fb65ab91
BLAKE2b-256 d17cc413c2cac16ee2746d8e33e800eed6f3c5049511835ef2e01a819aba9b79

See more details on using hashes here.

File details

Details for the file ontologos-1.1.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ontologos-1.1.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e3a477f41a30a2f87174316cdb537c77306a933d2b9dc40392082e0b193d873
MD5 235448829e9483e49eb92f622ab203d6
BLAKE2b-256 7cb88909c41bad89c8e38829b65c1615953a04539c66df5c61777a6b0582209c

See more details on using hashes here.

File details

Details for the file ontologos-1.1.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ontologos-1.1.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 04ef397a9a8d08455b4b5374571f7c1b9ac9582c818e82e7ca9429f93352accf
MD5 5e9b5da9bde2dbe27ba6cea91b132124
BLAKE2b-256 e4528eb36b1fddb0a2ae3a4d7ca68f5112ed4f86ade09186d5d071692394f0eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page