OntoSQL
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.
Metadata
Release files for ontosql 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ontosql-0.5.0.tar.gz | 153.7 kB | Without provenance | Details for ontosql-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ontosql-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for ontosql-0.5.0-py3-none-any.whl |
Total release size: 243.4 kB
Release files / ontosql-0.5.0.tar.gz
| Download URL | ontosql-0.5.0.tar.gz |
|---|---|
| Size | 153.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
414dc10452c8e0ef0fc47581bf7f7a2450ca6dda64791da3595fd4be41befe17
|
|
BLAKE2b-256 checksum How to use checksums |
515c6370a8ad47aa56aefbc7927bae7cb5f057b03830891c5e1b10915c690fb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / ontosql-0.5.0-py3-none-any.whl
| Download URL | ontosql-0.5.0-py3-none-any.whl |
|---|---|
| Size | 89.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e325a215a8be448d981b632769fefed5b52028b693a0a446f0fd028302a75645
|
|
BLAKE2b-256 checksum How to use checksums |
62bfdabf80aaaa78b552ef890a80305654b220a37fad7e052b9b8cd7d00de4ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for ontosql 0.5.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.