ontolutils

Utility library for the work with ontologies.

https://github.com/matthiasprobst/ontology-utils

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Utility library for the work with ontologies.

Basic Info
Statistics
  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 20
Created almost 2 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License Citation Codemeta

README.md

Ontolutils - Object-oriented "Things"

Tests Status codecov Documentation Status pyvers Status

This package helps you in generating ontology-related objects and lets you easily create JSON-LD files.

Quickstart

Installation

Install the package:

bash pip install ontolutils

Usage

Imagine you want to describe a prov:Person with a first name, last name and an email address but writing the JSON-LD file yourself is too cumbersome and you want validation of the parsed parameters. The package lets you design classes, which describe ontology classes like this:

```python from pydantic import EmailStr, Field from pydantic import HttpUrl, model_validator

from ontolutils import Thing, urirefs, namespaces, as_id

@namespaces(prov="https://www.w3.org/ns/prov#", foaf="https://xmlns.com/foaf/0.1/", m4i='http://w3id.org/nfdi4ing/metadata4ing#') @urirefs(Person='prov:Person', firstName='foaf:firstName', lastName='foaf:lastName', mbox='foaf:mbox', orcidId='m4i:orcidId') class Person(Thing): firstName: str lastName: str = Field(default=None, alias="lastname") # you may provide an alias mbox: EmailStr = Field(default=None, alias="email") orcidId: HttpUrl = Field(default=None, alias="orcidid")

# the following will ensure, that if orcidId is set, it will be used as the id
@model_validator(mode="before")
def _change_id(self):
    return as_id(self, "orcidId")

p = Person(id="https://orcid.org/0000-0001-8729-0482", firstName='Matthias', last_name='Probst')

as we have set an alias, we can also use "lastName":

p = Person(id="https://orcid.org/0000-0001-8729-0482", firstName='Matthias', lastName='Probst')

The jsonld representation of the object will be the same in both cases:

jsonldserialization = p.modeldumpjsonld()

Alternatively use

serialized_str = p.serialize(format="json-ld") # or "ttl", "n3", "nt", "xml" ```

The result of the serialization is shown below:

json { "@context": { "owl": "http://www.w3.org/2002/07/owl#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", "prov": "https://www.w3.org/ns/prov#", "foaf": "https://xmlns.com/foaf/0.1/", "m4i": "http://w3id.org/nfdi4ing/metadata4ing#" }, "@id": "https://orcid.org/0000-0001-8729-0482", "@type": "prov:Person", "foaf:firstName": "Matthias", "foaf:lastName": "Probst" }

Define an ontology class dynamically:

If you cannot define the class statically as above, you can also define it dynamically:

```python from typing import List, Union

from ontolutils import build, Property, Thing

Event = build( namespace="https://schema.org/", namespaceprefix="schema", classname="Event", properties=[Property( name="about", default=None, property_type=Union[Thing, List[Thing]] )] ) conference = Event(label="my conference", about=[Thing(label='The thing it is about')]) ttl = conference.serialize(format="ttl") ```

The serialization in turtle format looks like this: ```turtle @prefix owl: http://www.w3.org/2002/07/owl# . @prefix rdfs: http://www.w3.org/2000/01/rdf-schema# . @prefix schema: https://schema.org/ .

[] a schema:Event ; rdfs:label "my conference" ; schema:about [ a owl:Thing ; rdfs:label "The thing it is about" ] . ```

Documentation

Please visit the documentation for more information.

Owner

  • Name: MatthiasProbst
  • Login: matthiasprobst
  • Kind: user
  • Location: Karlsruhe
  • Company: Karlsruhe Institute of Technology

I have fun programming with Python, whether it is for scientific or private projects. Most of my repos are related to fluid mechanics or data management.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: "Probst"
    given-names: "Matthias"
    orcid: "https://orcid.org/0000-0001-8729-0482"
title: "Ontolutils - Object-oriented Things"
version: 0.19.4
doi: 10.5281/zenodo.16887324
date-released: 2025-08-16
url: "https://github.com/matthiasprobst/ontology-utils"

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "license": "https://spdx.org/licenses/MIT",
  "codeRepository": "git+https://github.com/matthiasprobst/ontology-utils",
  "name": "ontolutils",
  "version": "0.21.1",
  "description": "Utility library for the work with ontologies.",
  "programmingLanguage": [
    "Python 3",
    "Python 3.9",
    "Python 3.10",
    "Python 3.11",
    "Python 3.12"
  ],
  "operatingSystem": [
    "Linux",
    "Windows",
    "macOS"
  ],
  "author": [
    {
      "@type": "Person",
      "@id": "https://orcid.org/0000-0001-8729-0482",
      "givenName": "Matthias",
      "familyName": "Probst",
      "email": "matthias.probst@kit.edu",
      "affiliation": {
        "@id": "https://ror.org/04t3en479",
        "@type": "Organization",
        "name": "Karlsruhe Institute of Technology, Institute of Thermal Turbomachinery"
      }
    }
  ]
}

GitHub Events

Total
  • Release event: 15
  • Watch event: 5
  • Push event: 54
  • Pull request event: 9
  • Create event: 33
Last Year
  • Release event: 15
  • Watch event: 5
  • Push event: 54
  • Pull request event: 9
  • Create event: 33

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 5
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 5
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • matthiasprobst (5)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 929 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 0
  • Total versions: 78
  • Total maintainers: 1
pypi.org: ontolutils

Utility library for the work with ontologies.

  • Versions: 78
  • Dependent Packages: 1
  • Dependent Repositories: 0
  • Downloads: 929 Last month
Rankings
Dependent packages count: 9.8%
Average: 37.1%
Dependent repos count: 64.4%
Maintainers (1)
Last synced: 7 months ago

Dependencies

docs/requirements.in pypi
  • Sphinx >=5,<6
  • sphinx_rtd_theme *
docs/requirements.txt pypi
  • alabaster ==0.7.12
  • babel ==2.10.3
  • certifi ==2022.6.15
  • charset-normalizer ==2.1.0
  • docutils ==0.17.1
  • idna ==3.3
  • imagesize ==1.4.1
  • jinja2 ==3.1.2
  • markupsafe ==2.1.1
  • myst-nb *
  • packaging ==21.3
  • pydantic *
  • pygments ==2.12.0
  • pyparsing ==3.0.9
  • python-dateutil *
  • pytz ==2022.1
  • rdflib *
  • requests *
  • requests ==2.28.1
  • scikit-image *
  • scikit-learn *
  • simplejson *
  • snowballstemmer ==2.2.0
  • sphinx ==5.0.2
  • sphinx-copybutton *
  • sphinx-design *
  • sphinx-rtd-theme ==1.0.0
  • sphinxcontrib-applehelp ==1.0.2
  • sphinxcontrib-devhelp ==1.0.2
  • sphinxcontrib-htmlhelp ==2.0.0
  • sphinxcontrib-jsmath ==1.0.1
  • sphinxcontrib-qthelp ==1.0.3
  • sphinxcontrib-serializinghtml ==1.1.5
  • urllib3 ==1.26.9
setup.py pypi
.github/workflows/tests.yml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • codecov/codecov-action v3 composite
pyproject.toml pypi
requirements-dev.txt pypi
  • pytest >=7.1.2 development
  • pytest-cov * development
  • pyyaml >6.0.0 development
  • xmltodict * development
requirements.txt pypi
  • pydantic *
  • python-dateutil *
  • rdflib *
  • requests *