SparqlModel Project Plan
Vision
SparqlModel — the SQLModel of SPARQL.
SparqlModel is a SPARQL ORM for application developers. It requires TripleModel >=0.10 and focuses exclusively on what TripleModel does not provide: sessions, a query compiler, store backends, cascade persistence policy, and hydration depth.
TripleModel is the mapping substrate — literals, terms, sync_to_graph, from_graph, and file parse/serialize. SparqlModel does not compete with it; SPARQLModel subclasses TripleModel (Option A) so there is one class and one mapping path.
Guides: ORM.md · ECOSYSTEM.md · ROADMAP.md · SPECS.md · PRODUCTION.md
Production ORM definition (1.3 GA north star)
SparqlModel 1.2 means a fully featured production SPARQL ORM — the SQLModel of SPARQL for backend and FastAPI teams:
Correctness — One mapping path via
SPARQLModel(TripleModel); cascade/orphan rules covered by contract tests.Session parity — Identity map, pending flush,
expire/refresh/merge/expunge, scoped session for FastAPI, documented threading.Query parity — Pagination (
offset+limit), sorting,count(), filters including null/absence on relationships.RDF fidelity — Multi-valued fields, language tags (TripleModel), polymorphic
rdf:typequeries where modeled.Operational stores — Production
HttpStore(read/write URLs, mirror contract, retries);MemoryStorefor tests.Production hooks — Optional SHACL on
put, query logging, bulk operations.
Explicit non-goals: OWL editor, built-in reasoner, reimplementing TripleModel in graph.py.
GA gate: SPECS.md — Production checklist.
Parity tiers
Tier |
Meaning |
Examples |
|---|---|---|
P0 |
Required for production HTTP/API apps |
Unified |
P1 |
SQLModel / SPARQLMojo parity |
Full ROADMAP parity backlog: modeling 0.13, ops 0.14 |
P2 |
Advanced / ecosystem |
Named graphs, federation, CONSTRUCT/ASK helpers, Oxigraph store |
Competitive positioning
SparqlModel |
Raw rdflib |
||
|---|---|---|---|
Session + query DSL |
Yes |
Yes |
Manual |
TripleModel mapping |
Required |
No |
N/A |
FastAPI |
Yes |
No |
Manual |
Cascade |
Yes |
Partial |
Manual |
Python 3.10+ |
Yes |
3.12+ |
Yes |
SparqlModel wins on integrated mapping (TripleModel), FastAPI, async HTTP, composition semantics, and documented store contracts. SPARQLMojo leads on lang/collections, property paths, ontology-aware queries until 0.13 (see parity backlog).
Product positioning
SparqlModel (ORM)
Entry point:
with SPARQLSession() as session:SQLModel-style models:
SPARQLModel(subclassesTripleModel),Field,RelationshipPython queries → SPARQL:
session.query(Person).where(Person.name == x)Unit-of-work semantics:
add,put,delete, cascade, orphansStores:
MemoryStore,HttpStore(sparqlmodel[http])
Not SparqlModel: mapping correctness, XSD registries, Turtle parsers, or stateless ETL — that is TripleModel.
TripleModel (required dependency)
PyPI:
triplemodel· pinned in SparqlModel as>=0.10.0,<2(withpyoxigraph>=0.5,<0.6)Stateless Pydantic ↔ RDF; API frozen from TripleModel 0.9 until 1.0
SparqlModel routes new mapping features through TripleModel first
TripleModel |
SparqlModel |
|
|---|---|---|
Question |
“Are these triples correct?” |
“How do I run my app on a graph?” |
State |
Stateless |
Stateful session |
Grow here |
Terms, files, Dataset, SHACL |
Compiler, stores, cascade, FastAPI |
ORM thesis
SparqlModel exists to answer: “How do I build and operate an application on RDF?”
Owned by SparqlModel (now and always):
SPARQLSession— CRUD and graph sync with a storeQuery DSL and SPARQL compiler
Cascade and orphan policy on
put/deleteHydration depth on
getand query resultsPluggable stores (
MemoryStore,HttpStore, …)Optional FastAPI integration
Owned by TripleModel (SparqlModel delegates via subclass):
Model ↔ triple conversion
Literal and IRI term handling
sync_to_graph/from_graph/parse/serializeMulti-valued fields, nested embeds, blank nodes (per TripleModel roadmap)
Public ORM API stays stable (Field, Relationship, session.put) while internals move to Option A (delete _triple.py adapter in 0.4) and serializers.py is retired in 0.6.
Architecture (Option A)
Application
↓
SPARQLModel(TripleModel) · Field/Relationship sugar · Query metaclass
↓
SPARQLSession · Compiler · Stores · graph.py (cascade only) ← SparqlModel
↓
sync_to_graph · from_graph · terms · files ← TripleModel (same instance type)
↓
pyoxigraph · triplemodel · pydantic
Never in SparqlModel: duplicate python_to_term, new RDF format parsers, dynamic shadow TripleModel classes (exec adapter), or session-free mapping APIs.
Never in TripleModel: SPARQLSession, query compiler, cascade put, or HTTP store plugins.
Integration strategy
SparqlModel depends on triplemodel>=0.10 and pyoxigraph (0.5+). Remaining work: async sessions, file I/O consolidation, and production features.
Phase |
SparqlModel |
TripleModel usage |
|---|---|---|
0.1.x |
ORM shipped; interim |
Dependency declared |
0.2 |
|
Contract tests |
0.3 |
Session I/O via adapter (interim bridge) |
|
0.4 |
Unified model (Option A) — |
Direct |
0.5 |
Pyoxigraph + TM 0.10 ( |
— |
0.6 |
Async end-to-end ( |
— |
0.7 |
Delegated file I/O |
Thin |
0.8 |
Query lists |
|
0.9 |
Session cache |
|
0.10–0.12 |
Mirror semantics, HTTP resilience, GSP sync |
|
0.13 |
SPARQLMojo modeling parity |
Multi-valued, lang, polymorphic query, property paths, inverse/VALUES |
0.14 |
Production operations |
SHACL hook, bulk, ASK/CONSTRUCT, |
0.15 |
Production GA |
SPECS P0+P1 complete; stable public API |
Primary goals
P0 (production APIs):
Unified model (Option A) —
SPARQLModel(TripleModel); one mapping path (0.4)Pyoxigraph engine —
triplemodel.Storefor session graphs (0.5, shipped)Async ORM —
AsyncSPARQLSession, async stores, FastAPIAsyncSessionDep(0.6)Typed SPARQL persistence with explicit
add/put/deletesemanticsPythonic filters compiled to SPARQL (including pagination and sorting)
Relationship hydration with
depth; nullable relationship filtersOperational stores with documented HttpStore mirror semantics
Lean on TripleModel for all mapping and file I/O
P1 (parity):
Session lifecycle aligned with SQLAlchemy (
merge,refresh,expunge)Multi-valued and language-tagged fields via TripleModel
Polymorphic queries and optional inverse relationships
Cross-cutting:
Stable
SPARQLModel/Field/session.putdeveloper experienceFastAPI session injection and content negotiation
Target users
FastAPI and backend teams
Knowledge-graph product engineers
Enterprise metadata and AI infrastructure
Anyone who would reach for SQLModel if the database were RDF
Technology stack
Required: pydantic>=2.5,<3, pyoxigraph>=0.5,<0.6, triplemodel>=0.10.0,<2, typing-extensions
Optional extras: httpx (HTTP store), fastapi
SHACL: triplemodel[shacl] — optional hook on session.put, not in SparqlModel core
Development: pip install -e ".[dev]" and optionally pip install -e ../triplemodel
Releases (summary)
Version |
Theme |
|---|---|
0.1.x |
Core ORM + cascade |
0.2 |
HttpStore, identity map, compiler 0.2, FastAPI |
0.3 |
TripleModel session I/O via interim adapter (shipped) |
0.4 |
Unified model (Option A) |
0.5 |
Pyoxigraph + TripleModel 0.10 |
0.6 |
Async end-to-end |
0.7 |
Delegated file I/O |
0.8 |
Query lists |
0.9 |
Session cache |
0.10–0.12 |
Production HttpStore |
0.13 |
SPARQLMojo modeling parity |
0.14 |
Production operations |
0.15 |
Production GA |
Detail: ROADMAP.md
Risks
Reimplementing TripleModel in
graph.pyinstead of keeping cascade-only policyORM scope creep (reasoning, ontology editing)
Performance without identity map on large graphs
Metaclass +
TripleModel.__pydantic_init_subclass__ordering when merging query DSL with mapping validationDiverging
Fieldsugar from TripleModelrdf_field/PredicatemetadataDocumenting features as shipped when only planned (keep ROADMAP / SPECS in sync)
HttpStore mirror in multi-tenant or multi-writer deployments without sync strategy
Strategy
TripleModel first for any mapping, literal, or format bug
SparqlModel first for session, compiler, cascade, stores
Option A before async — unified model (0.4), pyoxigraph engine (0.5), then async (0.6), then pagination and HttpStore
Preserve ORM public API (
Field,Relationship,session.put); change internals on unifiedSPARQLModel(TripleModel)baseDocument semantics in ORM.md, SPECS.md, PRODUCTION.md
Contract tests: SparqlModel
puttriple sets align with TripleModelsync_to_graph+ cascade rulesSPECS Production checklist is the 1.3 GA gate