Turn free text into a typed object graph — classes, objects, properties, actions, relationships, rules, and events — with any LLM.
Project description
ontonym-core
Turn free text into a typed object graph — classes, properties, actions, relationships, rules, plus objects and events — using any LLM.
import asyncio
from ontonym_core import extract
result = asyncio.run(extract(
"Sarah deployed PaymentService at 14:02. "
"An outage hit it at 14:05, affecting the payments flow.",
backend="ollama",
))
print(result.model_dump_json(indent=2))
{
"classes": {
"classes": [
{"name": "person", "description": "A human", "inherited_from": null},
{"name": "application", "description": "A deployable service", "inherited_from": null},
{"name": "outage", "description": "A service outage", "inherited_from": "event"}
],
"actions": [{"name": "deploy", "actor": "person", "target": "application"}],
"relationships": [{"source": "outage", "target": "application", "type": "affected"}],
"rules": []
},
"objects": {
"objects": [
{"class_name": "person", "name": "sarah", "display_name": "Sarah"},
{"class_name": "application", "name": "payment_service", "display_name": "PaymentService"}
],
"events": [
{"class_name": "outage", "name": "outage_1405", "display_name": "outage at 14:05"}
],
"actions": [
{"action_name": "deploy", "actor": "sarah", "target": "payment_service", "occurred_at": "14:02"}
],
"relationships": [
{"source": "outage_1405", "target": "payment_service", "type": "affected"}
]
}
}
Local-first — run it with Ollama and no API key. Or switch to Anthropic Claude when you want speed.
Status: 0.x is unstable. APIs may change between minor versions until 1.0.
What it does
Two extraction passes, run in sequence:
- Class layer (
classes,properties,actions,relationships,rules) — the schema. What kinds of things exist in this text? - Object layer (
objects,events,object_properties,object_actions,object_relationships) — the instances. What specific things are mentioned, and what did they do?
Events are first-class: actor-less, time-anchored happenings (incidents, outages, deployments, decisions, market events) are emitted separately from actor-driven actions.
Install
pip install ontonym-core
# Optional extras:
pip install 'ontonym-core[anthropic]' # adds Anthropic Claude backend
pip install 'ontonym-core[server]' # adds FastAPI example server
Quickstart — Ollama (local, no API key)
# One-time setup
ollama serve # in another terminal
ollama pull llama3.1:8b
pip install ontonym-core
# CLI
ontonym-core extract --text "Sarah deployed prod at 14:02"
# Or stream from stdin
cat notes.txt | ontonym-core extract --mode both
# Health check
ontonym-core health --backend ollama
Quickstart — Anthropic (hosted Claude)
pip install 'ontonym-core[anthropic]'
export ANTHROPIC_API_KEY=sk-ant-...
ontonym-core extract --text "..." --backend anthropic
Python API
import asyncio
from ontonym_core import extract, extract_classes, extract_objects, OllamaBackend
# One-shot: class pass + object pass against the resulting schema.
result = asyncio.run(extract(
"Marcus closed Acme's renewal on 2024-11-18.",
backend="ollama",
))
# Or run passes separately for full control.
backend = OllamaBackend(model="llama3.1:8b")
schema = asyncio.run(extract_classes("...", backend=backend))
objects = asyncio.run(extract_objects("...", schema, backend=backend))
# Diff-only iteration: feed the prior accumulator to skip already-known rows.
schema_v2 = asyncio.run(extract_classes("more text...", backend=backend, prior=schema))
The result models are plain Pydantic — .model_dump_json() for JSON, .model_dump() for dicts, and full type hints for IDE autocomplete.
Custom backends
A backend is anything implementing Backend from ontonym_core.llm — two async methods (extract_classes, extract_objects) and one health probe (check_health). You can wire OpenAI, Together, Groq, or your own gateway by reusing the parsers:
from ontonym_core import parse_class_json, parse_object_json, ClassExtraction
class MyBackend:
async def extract_classes(self, text, prior):
raw = await my_llm.generate(prompt_for_classes(text, prior))
return parse_class_json(raw)
# ... extract_objects, check_health similarly
FastAPI example
pip install 'ontonym-core[server]'
uvicorn examples.server:app --reload
curl -X POST http://localhost:8000/extract \
-H 'content-type: application/json' \
-d '{"text": "...", "mode": "both"}'
See examples/server.py — single route, ~50 lines.
What's not in here
Deliberately out of scope:
- Storage —
ontonym-coreis stateless. Persist the JSON to whatever fits your stack (Postgres, DuckDB, plain files). - Multi-tenancy / access control — same.
- Flow detection (recurring patterns across action+event timelines) — held back.
- Approval workflows — what makes a graph trustworthy is a product problem, not an extractor problem.
If you want those out of the box, see ontonym.com — the hosted product that this library was carved out of.
How this fits with ontonym (hosted)
The hosted product at ontonym.com depends on ontonym-core. Same prompts, same parsers, same Pydantic models. What hosted adds on top:
- Postgres + pgvector storage with provenance (every fact tied to its source document)
- Per-tenant isolation + per-row access grants
- Approval workflow (the "Object Guru" reviews / merges / rejects)
- Flow detection across time-ordered actions
- An MCP server so AI agents read the graph as a tool
- Slack / Teams / Notion / Salesforce / HubSpot / GitHub / Linear / Jira connectors
If you build something cool on top of ontonym-core, drop a note — we'd love to see it.
License
Apache 2.0. See LICENSE.
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
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 ontonym_core-0.2.0.tar.gz.
File metadata
- Download URL: ontonym_core-0.2.0.tar.gz
- Upload date:
- Size: 34.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d86dc58470a24b43ac57e0fec88ca9f2490b757f33f8772fbfdb709e6395cf30
|
|
| MD5 |
5a0ff394179d3177725441c7830904b7
|
|
| BLAKE2b-256 |
36ded70a4111cbd8194f641fff594fc2475d86a954db862fcaec16929688912b
|
Provenance
The following attestation bundles were made for ontonym_core-0.2.0.tar.gz:
Publisher:
release.yml on serkan-uz/ontonym-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ontonym_core-0.2.0.tar.gz -
Subject digest:
d86dc58470a24b43ac57e0fec88ca9f2490b757f33f8772fbfdb709e6395cf30 - Sigstore transparency entry: 1571009897
- Sigstore integration time:
-
Permalink:
serkan-uz/ontonym-core@a3888fa981b39464986a247c2341bc2b52f7055d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/serkan-uz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3888fa981b39464986a247c2341bc2b52f7055d -
Trigger Event:
push
-
Statement type:
File details
Details for the file ontonym_core-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ontonym_core-0.2.0-py3-none-any.whl
- Upload date:
- Size: 45.6 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 |
0b4bd4080f1f06c2f09fd9cfd2399bdca15308646332b7f8c12cd81ef50d6919
|
|
| MD5 |
6a23d99e2a40555a06ba0661bd4752ca
|
|
| BLAKE2b-256 |
d17ce31120d59fdbfc3066cc874cb61d74d913847035c039edf15b1d79f44387
|
Provenance
The following attestation bundles were made for ontonym_core-0.2.0-py3-none-any.whl:
Publisher:
release.yml on serkan-uz/ontonym-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ontonym_core-0.2.0-py3-none-any.whl -
Subject digest:
0b4bd4080f1f06c2f09fd9cfd2399bdca15308646332b7f8c12cd81ef50d6919 - Sigstore transparency entry: 1571010077
- Sigstore integration time:
-
Permalink:
serkan-uz/ontonym-core@a3888fa981b39464986a247c2341bc2b52f7055d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/serkan-uz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3888fa981b39464986a247c2341bc2b52f7055d -
Trigger Event:
push
-
Statement type: