rdflib-reasoning
rdflib-reasoning is a family of Python packages for RDFLib graph
axiomatization, RETE-based RDFS and OWL 2 RL entailment, support-aware
retraction, inspectable proofs, contradiction diagnostics, and semantic-web
middleware.
The packages are designed for ordinary RDFLib use first, while also supporting research into tool-grounded Research Agents that reason over RDF graphs and formal logic systems.
Installation
Install the published metapackage:
pip install rdflib-reasoning
That install pulls in the repository's published component packages:
rdflib-reasoningrdflib-reasoning-axiomsrdflib-reasoning-enginerdflib-reasoning-middleware
If you only need part of the system, you can also install the component packages directly from PyPI.
Quickstart
The basic RDFS inference path uses an ordinary RDFLib dataset backed by the reasoning store:
from rdflib import Namespace
from rdflib.namespace import RDF, RDFS
from rdflib_reasoning.engine import RDFS_RETE_MATERIALIZED
EX = Namespace("urn:example:")
dataset = RDFS_RETE_MATERIALIZED.dataset()
graph = dataset.default_graph
alice = EX.alice
person = EX.Person
mammal = EX.Mammal
animal = EX.Animal
graph.add((alice, RDF.type, person))
graph.add((person, RDFS.subClassOf, mammal))
graph.add((mammal, RDFS.subClassOf, animal))
assert (alice, RDF.type, animal) in graph
Because the reasoning store is wired through ordinary RDFLib graph events,
statement retraction uses the normal graph.remove(...) API:
graph.remove((alice, RDF.type, person))
assert (alice, RDF.type, animal) not in graph
Contradiction detection is also available through the same engine path: extend
a reasoner specification with the appropriate contradiction rules, and the
default recorder records the diagnostic before raising
ContradictionDetectedError.
Component Packages
| Package | Purpose |
|---|---|
rdflib-reasoning |
Metapackage for the published library family |
rdflib-reasoning-axioms |
Graph axiomatization primitives |
rdflib-reasoning-engine |
RETE-based RDFS and OWL 2 RL entailment |
rdflib-reasoning-middleware |
Semantic-web middleware and Research Agent-facing data interchange |
Repository Layout
| Path | Purpose |
|---|---|
| notebooks | Analysis notebooks and research experiments |
| rdflib-reasoning-axioms | Graph axiomatization primitives |
| rdflib-reasoning-engine | RETE-based RDFS and OWL 2 RL entailment |
| rdflib-reasoning-middleware | Middleware and Research Agent-facing data interchange |
| docs/dev | Architecture notes, decision records, and development guidance |
| docs/specs | Cached specifications optimized for development work |
API and developer documentation is published at
rdflib-reasoning documentation.
It can also be generated locally with make docs and served with
make docs-serve.
Examples And Notebooks
The checked-in notebooks provide tutorial paths, demonstrations, and research experiments:
- notebooks/demo-rdfs-inference.ipynb: shortest end-to-end walkthrough of RDFLib-backed RDFS materialization plus a proof view showing which rule applications justify one inferred triple
- notebooks/demo-owl2-rl-inference.ipynb: OWL 2 RL counterpart showing class-equivalence and subclass typing materialization plus proof inspection for one inferred triple
- notebooks/demo-rdfs-retraction.ipynb: update-aware companion showing that ordinary statement removal retracts dependent RDFS inferences
- notebooks/demo-contradiction-rules.ipynb: OWL 2 RL contradiction diagnostics when contradiction rules are included in the active ruleset
- notebooks/demo-proof-reconstructor.ipynb:
proof-focused companion notebook covering Mermaid rendering, markdown
rendering, and raw
DirectProofinspection - notebooks/README.md: notebook index with suggested reading order for demos and experiments
Research And Evaluation
The repository also supports one practical research question:
When do tool-grounded Research Agent harnesses outperform direct prompting on multi-step formal reasoning tasks that require external knowledge retrieval, knowledge-base updates, and verifiable inference?
Research on agents takes place in Analysis Notebooks, uses the LangChain ecosystem, and depends on packages defined in this repository. Those packages build on RDFLib for semantic-web support and on Pydantic for Research Agent-friendly schemas.
---
config:
theme: 'base'
---
block-beta
columns 3
Notebooks("Analysis Notebooks"):3
Deepagents:1 ReasoningMiddleware["rdflib-reasoning-middleware"]:2
LangGraph:2
block:RdflibAbstraction:1
columns 1
Reasoning["rdflib-reasoning-engine"]:1
Axioms["rdflib-reasoning-axioms"]:1
end
LangChain:2 RDFLib:1
%% Agent Note: The remainder of this block is styling for humans and can be ignored
classDef Research fill:#fdb462,stroke:black
class Notebooks Research
classDef LangChainEcosystem fill:#80b1d3,stroke:blue
class Deepagents,LangGraph,LangChain LangChainEcosystem
classDef SupportingPackage fill:#b3de69,stroke:black
class ReasoningMiddleware,Reasoning,Axioms SupportingPackage
classDef SemanticWeb fill:#ccebc5,stroke:darkgreen
class RDFLib SemanticWeb
Reviewer Guide
For agent-assisted review, use the project critique skill at
.cursor/skills/critique-project/SKILL.md.
If your tool does not discover .cursor skills automatically, open the skill
file and ask your coding agent to follow it. For manual review, start here:
- Read this file for the package purpose, install path, and repository layout.
- Read docs/dev/architecture.md for the current technical direction.
- Inspect rdflib-reasoning-engine for the reasoning core.
- Inspect rdflib-reasoning-middleware for Research Agent integration.
- Inspect notebooks for the research surface and experiments.
Repository Roles
This repository distinguishes between two agent types. Canonical definitions are in AGENTS.md.
- Research Agent: The deployed or runtime agent that is the subject of research. It sees middleware, tools, system prompts, and generated schema; it does not see the repository or design documentation.
- Development Agent: The code agent that reads repository documentation, modifies code and docs, and develops code for the Research Agent.
Contributing
For local development setup, validation commands, notebook contribution guidance, and publishing policy, see .github/CONTRIBUTING.md.
If you are using these packages from another project, install the published packages from PyPI and start with the published documentation. Use the monorepo checkout when you need to modify package code, contribute notebooks, or inspect unpublished changes.
Why This Repository Exists
RDFLib does not by itself provide a clean path for graph axiomatization, support-aware entailment, Research Agent-oriented schema exposure, and inspectable reasoning workflows. This repository packages those concerns into reusable libraries so Python projects can build on dependable semantic-web reasoning infrastructure, while the included notebooks show how that infrastructure supports formal-logic experiments with agents.
Metadata
Release files for rdflib-reasoning 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rdflib_reasoning-0.5.0.tar.gz | 752.3 kB | With provenance | Details for rdflib_reasoning-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rdflib_reasoning-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for rdflib_reasoning-0.5.0-py3-none-any.whl |
Total release size: 758.3 kB
Release files / rdflib_reasoning-0.5.0.tar.gz
| Download URL | rdflib_reasoning-0.5.0.tar.gz |
|---|---|
| Size | 752.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf53b094c37f923c9dc567abed366acba706625feb5d26f7cd166ed81d89908b
|
|
BLAKE2b-256 checksum How to use checksums |
f993901facfafbf0f4912fce725028a97877f0b01140dd6cdb4ae4ce288ba028
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / rdflib_reasoning-0.5.0-py3-none-any.whl
| Download URL | rdflib_reasoning-0.5.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47dee454c1dcb5b0c517f6ee3bca6f9a31a0c5dacba7c9eb2102e60300cdabe6
|
|
BLAKE2b-256 checksum How to use checksums |
c5388ab87e8f318ed1eccd5d630441db21eef23a4de4a8e3d28e756b73faab91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for rdflib-reasoning 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rdflib_reasoning-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.