Metadata-Version: 2.4
Name: ontosql
Version: 0.1.0
Summary: Semantic interoperability for SQLModel — JSON-LD and RDF export with ontology-aware fields (import ontosql)
Project-URL: Homepage, https://github.com/eddiethedean/ontosql
Project-URL: Documentation, https://github.com/eddiethedean/ontosql#readme
Project-URL: Repository, https://github.com/eddiethedean/ontosql
Project-URL: Issues, https://github.com/eddiethedean/ontosql/issues
Project-URL: Changelog, https://github.com/eddiethedean/ontosql/blob/main/CHANGELOG.md
Author: OntoSQL Contributors
License-Expression: MIT
License-File: LICENSE
Keywords: fastapi,json-ld,ontology,rdf,semantic-web,sqlmodel
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: rdflib>=7.0.0
Requires-Dist: sqlmodel>=0.0.14
Requires-Dist: typing-extensions>=4.0
Provides-Extra: dev
Requires-Dist: fastapi>=0.100; extra == 'dev'
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: orjson>=3.9; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest-cov>=5; extra == 'dev'
Requires-Dist: pytest-xdist>=3.8; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: ty>=0.0.37; extra == 'dev'
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.100; extra == 'fastapi'
Requires-Dist: orjson>=3.9; extra == 'fastapi'
Description-Content-Type: text/markdown

# OntoSQL

**Semantic interoperability for SQLModel** — enrich operational models with ontology metadata and export JSON-LD and RDF without leaving Python.

```bash
pip install ontosql
pip install "ontosql[fastapi]"   # optional API helpers
```

## Quick start

```python
from sqlmodel import Field, SQLModel
from ontosql import OntoMixin, onto_field, onto_model


@onto_model(type_="schema:Person", iri_template="http://example.org/person/{id}")
class Person(SQLModel, OntoMixin, table=False):
    id: int | None = Field(default=None, primary_key=True)
    name: str = onto_field(ontology="schema:name")


person = Person(id=1, name="Ada Lovelace")
print(person.to_jsonld())
print(person.to_rdf(format="turtle"))
```

## Features (0.1.0)

- `onto_field()` — attach ontology CURIEs/IRIs to model fields
- `onto_model()` — declare RDF type and instance IRI templates on classes
- `PrefixRegistry` — manage namespace prefixes for JSON-LD `@context`
- `to_jsonld()` / `to_rdf()` — export instances to semantic web formats
- FastAPI response helpers with content negotiation (`ontosql[fastapi]`)

## FastAPI

```python
from fastapi import FastAPI, Request
from ontosql.fastapi import negotiate_onto_response

app = FastAPI()

@app.get("/person/{person_id}")
def get_person(person_id: int, request: Request):
    person = Person(id=person_id, name="Ada Lovelace")
    return negotiate_onto_response(request, person)
```

See [examples/fastapi_demo.py](https://github.com/eddiethedean/ontosql/blob/main/examples/fastapi_demo.py).

## Limitations (0.1.0)

- No RDF import or SHACL generation yet (planned for 0.2+)
- Foreign-key-only relationships export as `@id` references, not nested objects (use a nested `OntoMixin` field for embedded objects)
- JSON-LD framing requires a future `ontosql[jsonld]` extra (PyLD)
- Do not map two fields to the same ontology property; if you do, nested objects are preferred over FK integers (a warning is emitted)

## Documentation

- [Roadmap](https://github.com/eddiethedean/ontosql/blob/main/docs/ROADMAP.md)
- [Technical specification](https://github.com/eddiethedean/ontosql/blob/main/docs/SPECS.md)
- [Project plan](https://github.com/eddiethedean/ontosql/blob/main/docs/PLAN.md)
- [Dependency assessment](https://github.com/eddiethedean/ontosql/blob/main/docs/DEPS.md)
- [Changelog](https://github.com/eddiethedean/ontosql/blob/main/CHANGELOG.md)

## Development

See [Releasing](https://github.com/eddiethedean/ontosql/blob/main/docs/RELEASING.md) for the version publish checklist.

```bash
pip install -e ".[dev]"
ruff check src tests
ruff format src tests
ty check
pytest --cov=ontosql --cov-fail-under=100
```

## License

MIT — see [LICENSE](https://github.com/eddiethedean/ontosql/blob/main/LICENSE).
