Root ontology in LinkML for ontology-typed knowledge graphs with write-time validation and content-addressable convergence
Project description
Malleus
A root ontology in LinkML plus a reference implementation of ontology-typed knowledge graphs with write-time validation and content-addressable hashing for distributed convergence.
What it is
Five universal primitives (Entity, Event, Signal, Agent, Relation) plus four cross-cutting mixins (Identifiable, Temporal, Describable, Statusable). Domain extensions add typed classes and enums that build on the root. The OntologyRegistry is the constructor parameter for the knowledge graph: no registry, no KG. Every write is validated at the boundary.
Install
pip install malleus-dev
# Optional Prolog verification layer (requires SWI-Prolog on the system)
pip install malleus-dev[prolog]
Quick start
from malleus import OntologyRegistry, KnowledgeGraph
reg = OntologyRegistry("ontology/domains/cyp450.yaml")
kg = KnowledgeGraph(reg)
kg.create_entity("Enzyme", "enz-cyp3a4", {"name": "CYP3A4", "cyp_isoform": "CYP3A4"})
kg.create_entity("Drug", "drug-sim", {"name": "Simvastatin"})
kg.create_relation("DrugRelation", "rel-001", "drug-sim", "enz-cyp3a4",
{"relation_type": "SUBSTRATE_OF"})
# Write-time validation: invalid types and enum values are rejected with feedback.
op = kg.create_entity("NotAType", "x", {})
assert op.op_status.value == "REJECTED"
print(op.rejection_reason) # "Unknown entity type: 'NotAType'"
Ontology hashing and distributed convergence
Every registry has a deterministic content hash and a fingerprint of atomic facts. Two instances can verify compatibility without exchanging full schemas.
reg = OntologyRegistry("ontology/domains/cyp450.yaml")
print(reg.content_hash()) # 64-char SHA-256 hex, deterministic
print(len(reg.fingerprint())) # frozenset of atomic facts (types, enums, slots, inheritance)
# Check compatibility against another peer's ontology:
result = reg.check_compatibility(foreign_hash, foreign_fingerprint)
# -> "identical" | "superset" | "subset" | "divergent"
Under additive-only evolution (adding types, enum values, or slots; relaxing required constraints), a newer ontology's fingerprint is always a strict superset of an older one's. This lets peers in a distributed KG safely exchange operations tagged with their ontology hash: receivers accept what they understand and quarantine what they don't until they upgrade.
Domain extensions
Two example domain extensions ship with the library. Write your own the same way.
# your_domain.yaml
id: https://example.org/schema/your_domain
name: your_domain
imports:
- malleus
- linkml:types
classes:
YourEntity:
is_a: Entity
slot_usage:
your_slot:
required: true
range: YourEnum
enums:
YourEnum:
permissible_values:
VALUE_A: {}
VALUE_B: {}
Optional: Prolog verification
For domains where logical consistency matters (pharmacology, security threat modeling, regulatory rules), the PrologVerifier syncs the KG into SWI-Prolog and checks proposed writes against a rule file you supply.
from malleus import PrologVerifier
verifier = PrologVerifier("your_rules.pl")
result = verifier.verify_proposed_relation(
kg,
source_id="drug-a",
target_id="enz-x",
relation_type="INHIBITS",
properties={"strength": "strong"},
)
if not result.valid:
print(f"Rule violation: {result.rule_violated}")
print(result.proof_trace)
Architecture
See docs/ARCHITECTURE.md for a layer-by-layer walkthrough: vocabulary, typed graph, ground truth loading, logic engine, distributed convergence.
Protocols:
docs/ONTOLOGY_PROTOCOL.md— how to adopt malleus in a new projectdocs/KNOWLEDGE_GRAPH_PROTOCOL.md— how the ontology shapes the KG
Tests
pip install -e .[prolog,dev]
pytest tests/ -v
# 95 tests pass in ~3 seconds
License
Apache-2.0. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file malleus_dev-0.1.0.tar.gz.
File metadata
- Download URL: malleus_dev-0.1.0.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a78c9ec8634e416222d5d57e73751a08b94a2bf5ecf4a612aadc44e173a67473
|
|
| MD5 |
257897dd12de940106cfd344c778f79f
|
|
| BLAKE2b-256 |
e699205d65f4020f911ebb2c366f9e0e1117814c99764373727bc0cbb9f0a44f
|
Provenance
The following attestation bundles were made for malleus_dev-0.1.0.tar.gz:
Publisher:
release.yml on Kieleth/malleus-dev
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
malleus_dev-0.1.0.tar.gz -
Subject digest:
a78c9ec8634e416222d5d57e73751a08b94a2bf5ecf4a612aadc44e173a67473 - Sigstore transparency entry: 1282368100
- Sigstore integration time:
-
Permalink:
Kieleth/malleus-dev@c8d335d9c608aeb20ac10381130338c74f43e5ea -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Kieleth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8d335d9c608aeb20ac10381130338c74f43e5ea -
Trigger Event:
push
-
Statement type:
File details
Details for the file malleus_dev-0.1.0-py3-none-any.whl.
File metadata
- Download URL: malleus_dev-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0ae0a53331be14c058b27c10e2d71fde9ef24f62f26ac07d815a7e320c65067
|
|
| MD5 |
a6f3138290b51f7a62437a3f797738df
|
|
| BLAKE2b-256 |
b671bff0ef3c858f733002c58af17dec654d66bc60d82a08013c4ac3b239bf08
|
Provenance
The following attestation bundles were made for malleus_dev-0.1.0-py3-none-any.whl:
Publisher:
release.yml on Kieleth/malleus-dev
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
malleus_dev-0.1.0-py3-none-any.whl -
Subject digest:
a0ae0a53331be14c058b27c10e2d71fde9ef24f62f26ac07d815a7e320c65067 - Sigstore transparency entry: 1282368130
- Sigstore integration time:
-
Permalink:
Kieleth/malleus-dev@c8d335d9c608aeb20ac10381130338c74f43e5ea -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Kieleth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8d335d9c608aeb20ac10381130338c74f43e5ea -
Trigger Event:
push
-
Statement type: