Skip to main content

OntoSQL

PyPI version CI Python 3.10+ License: MIT Documentation

Semantic CRUD for SQL-first Python apps — SQLModel tables, Pydantic ontology models, explicit mappers, optional JSON-LD/RDF export.

0.5.x beta — API stability tiers in SPECS; semver guarantees begin at 1.0. Pin versions in production.

Not a SPARQL database or OBDA query engine. RDF and graph sync are optional extras.

Real databases rarely match ontology shapes one-to-one. OntoSQL separates physical SQLModel tables from semantic Pydantic entities and connects them with explicit mappers. Application code uses semantic types; OntoSQL compiles SQL on the backend.

Install

pip install ontosql
pip install "ontosql[async,fastapi]"   # optional extras — see docs

Requirements: Python 3.10+. See Compatibility.

Start here

I want to… Go to
Try CRUD in 5 minutes (pip only) Quick start
Pick a path (async, FastAPI, hybrid) Start here
Understand the design Architecture
Decide if OntoSQL fits When to use OntoSQL
Evaluate for production Security · Compatibility · Enterprise adoption

Full docs: ontosql.readthedocs.io

Minimal example

from sqlmodel import Field, Session, SQLModel, create_engine
from ontosql import Map, OntoMapper, OntoModel, OntoSession, onto_property

class PersonRow(SQLModel, table=True):
    __tablename__ = "people"
    id: int | None = Field(default=None, primary_key=True)
    name: str

class Person(OntoModel):
    type_iri = "schema:Person"
    iri_template = "https://data.example.org/person/{id}"
    id: int
    name: str = onto_property("schema:name")

class PersonMap(OntoMapper[Person]):
    entity = Person
    id = Map(PersonRow.id)
    name = Map(PersonRow.name, property="schema:name")

engine = create_engine("sqlite://")
SQLModel.metadata.create_all(engine)
with Session(engine) as raw:
    raw.add(PersonRow(id=1, name="Ada Lovelace"))
    raw.commit()
# Demo seeds via SQLModel; production code typically uses session.save() — see quickstart.

with OntoSession(engine, maps=[PersonMap]) as session:
    print(session.get(Person, identity=1).name)

Copy the full Person/Organization walkthrough from the quick start.

Ecosystem

Optional RDF export uses TripleModel. Graph-native apps can pair OntoSQL with SparqlModel. See Ecosystem.

Examples (repository clone)

The examples/ directory is not in the PyPI wheel:

git clone https://github.com/eddiethedean/ontosql.git
cd ontosql && pip install -e ".[dev]"
python examples/person_org_demo.py
Script What it teaches
person_org_demo.py Sync CRUD round-trip
person_org_async.py Async session
hybrid_person_org.py Graph sync, import
person_org_api_production.py Production FastAPI pattern

See examples/README.md for layout and how _bootstrap.py works.

Development

pip install -e ".[dev]"
ruff check src tests && ty check && pytest --cov=ontosql --cov-fail-under=90

See Contributing and Releasing.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ontosql-0.5.0.tar.gz (153.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ontosql-0.5.0-py3-none-any.whl (89.7 kB view details)

Uploaded Python 3

File details

Details for the file ontosql-0.5.0.tar.gz.

File metadata

  • Download URL: ontosql-0.5.0.tar.gz
  • Upload date:
  • Size: 153.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ontosql-0.5.0.tar.gz
Algorithm Hash digest
SHA256 414dc10452c8e0ef0fc47581bf7f7a2450ca6dda64791da3595fd4be41befe17
MD5 72de4ec5c0078436af2e0506e3b3c2a2
BLAKE2b-256 515c6370a8ad47aa56aefbc7927bae7cb5f057b03830891c5e1b10915c690fb6

See more details on using hashes here.

File details

Details for the file ontosql-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: ontosql-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 89.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ontosql-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e325a215a8be448d981b632769fefed5b52028b693a0a446f0fd028302a75645
MD5 c2b753b0e741fbbda52c37540dc3f2da
BLAKE2b-256 62bfdabf80aaaa78b552ef890a80305654b220a37fad7e052b9b8cd7d00de4ae

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page