Skip to main content

rdflib-reasoning

License: MIT Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

PyPI Version

Coverage

rdflib-reasoning is the metapackage for a family of Python libraries used to study how tool-grounded Research Agents interact with RDF graphs and formal reasoning systems. The source repository is organized as a multi-package workspace with supporting notebooks and development documentation.

The repository is organized around 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?

Reviewer Guide

If you are reviewing this repository quickly, start here:

  1. Read this file for the repository layout and install paths.
  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.

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 can be generated locally with make docs and served from the generated HTML output with make docs-serve.

Quickstart

If you want to see the repository's RDFS inference capabilities quickly, start with these checked-in notebooks:

If you prefer a minimal code-first example before opening a notebook, the basic RDFS inference path looks like this:

from rdflib import Dataset, Namespace
from rdflib.namespace import RDF, RDFS
from rdflib.plugins.stores.memory import Memory
from rdflib_reasoning.engine import PRODUCTION_RDFS_RULES, RETEEngineFactory
from rdflib_reasoning.engine.rete_store import RETEStore

EX = Namespace("urn:example:")

store = RETEStore(Memory(), RETEEngineFactory(rules=PRODUCTION_RDFS_RULES))
dataset = Dataset(store=store)
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: include the appropriate contradiction rules in RETEEngineFactory(rules=...), and the default recorder records the diagnostic before raising ContradictionDetectedError. The contradiction notebook shows how to choose recorder policy and inspect the resulting records.

Component Overview

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

Installation

Use the Published Packages

If you want to use the packaged system from another project, 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.

Work on This Repository Locally

Clone the repository and install the local workspace in editable mode:

pip install -e .

Add developer tooling:

pip install -e .[dev]

Add notebook and research dependencies:

pip install -e .[research]

Install the full local workspace:

pip install -e .[dev,research]

If you use uv, the equivalent commands are:

uv sync
uv sync --extra dev
uv sync --extra research
uv sync --extra dev --extra research

The root Makefile wraps those commands with install, install-dev, install-research, install-all, and notebook.

Add or Review Research Notebooks

If you want to contribute notebooks to this repository, or inspect the notebooks that already exist, install the repository locally with the research extra and work from the notebooks directory. The notebooks are part of the repository's research record rather than a separate published package. For the current demo/tutorial entry points, see notebooks/README.md.

Develop Against These Packages Elsewhere

If you are building another system on top of this work, the usual path is:

  1. Install the published packages from PyPI in your own project.
  2. Read docs/dev/architecture.md for the intended package boundaries.
  3. Use the monorepo checkout only 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, Research Agent-oriented schema exposure, and inspectable reasoning workflows. This repository packages those concerns into reusable libraries and research notebooks so that formal-logic experiments with agents are easier to build, evaluate, and explain.

Metadata

Release files for rdflib-reasoning 0.4.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.4.0
File Size Uploaded
rdflib_reasoning-0.4.0.tar.gz 595.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rdflib-reasoning 0.4.0
File Interpreter ABI Platform
rdflib_reasoning-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 602.1 kB

Release files / rdflib_reasoning-0.4.0.tar.gz

Download URL rdflib_reasoning-0.4.0.tar.gz
Size 595.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ca4d940aa4d23213b8522d311be2f53ceaa8bfe1e0000c9e8b113a1bb6c6f23c
BLAKE2b-256 checksum
How to use checksums
d43069eddd41224af6887f6479556ffdcc619ff5c8666c86809c809883fb46d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 30, 2026.

Transparency log

Release files / rdflib_reasoning-0.4.0-py3-none-any.whl

Download URL rdflib_reasoning-0.4.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04f6dd70c6074aac557006e18b2bf783e26758391371446a1212a35fc50b7057
BLAKE2b-256 checksum
How to use checksums
411eaf339896bc48b9b2eb177099b3b448a8cc3166f59515b08c89f444126f12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

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