Skip to main content

rdflib-reasoning

License: MIT Project Status: Active – The project has reached a stable, usable state and is being actively developed.

PyPI Version

Documentation

Coverage

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-reasoning
  • rdflib-reasoning-axioms
  • rdflib-reasoning-engine
  • rdflib-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:

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:

  1. Read this file for the package purpose, install path, and repository layout.
  2. Read docs/dev/architecture.md for the current technical direction.
  3. Inspect rdflib-reasoning-engine for the reasoning core.
  4. Inspect rdflib-reasoning-middleware for Research Agent integration.
  5. 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)

Source distribution for rdflib-reasoning 0.5.0
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)

Table of built distributions (wheels) for rdflib-reasoning 0.5.0
File Interpreter ABI Platform Actions
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 log

Release 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 log

Security 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.

Select from 2 files

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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page