Skip to main content

Ontolutils - Object-oriented "Things"

.. image:: https://github.com/matthiasprobst/ontology-utils/actions/workflows/tests.yml/badge.svg :target: https://github.com/matthiasprobst/ontology-utils/actions/workflows/tests.yml/badge.svg :alt: Tests Status

.. image:: https://codecov.io/gh/matthiasprobst/ontology-utils/branch/main/graph/badge.svg :target: https://codecov.io/gh/matthiasprobst/ontology-utils/branch/main/graph/badge.svg :alt: Coverage

.. image:: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue :target: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue :alt: pyvers Status

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

Quickstart

Installation


Install the package:

.. code-block:: 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:


.. code-block:: python

    from ontolutils import Thing, urirefs, namespaces
    from pydantic import EmailStr
    from rdflib import FOAF

    @namespaces(prov="http://www.w3.org/ns/prov#",
               foaf="http://xmlns.com/foaf/0.1/")
    @urirefs(Person='prov:Person',
             firstName='foaf:firstName',
             lastName=FOAF.lastName,
             mbox='foaf:mbox')
    class Person(Thing):
        firstName: str
        lastName: str = None
        mbox: EmailStr = None

    p = Person(id="local:cde4c79c-21f2-4ab7-b01d-28de6e4aade4",
               firstName='John', lastName='Doe')
    p.model_dump_jsonld()


Now, you can instantiate the class and use the `model_dump_jsonld()` method to get a JSON-LD string:

.. code-block:: json

    {
        "@context": {
            "owl": "http://www.w3.org/2002/07/owl#",
            "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
            "local": "http://example.org/",
            "lastName": "http://xmlns.com/foaf/0.1/",
            "prov": "http://www.w3.org/ns/prov#",
            "foaf": "http://xmlns.com/foaf/0.1/"
        },
        "@id": "local:cde4c79c-21f2-4ab7-b01d-28de6e4aade4",
        "@type": "prov:Person",
        "foaf:firstName": "John",
        "lastName": "Doe"
    }





Please visit the `documentation <https://ontology-utils.readthedocs.io/en/latest/>`_ for more information.

Download files

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

Source Distribution

ontolutils-0.2.2.tar.gz (624.1 kB view details)

Uploaded Source

Built Distribution

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

ontolutils-0.2.2-py3-none-any.whl (654.1 kB view details)

Uploaded Python 3

File details

Details for the file ontolutils-0.2.2.tar.gz.

File metadata

  • Download URL: ontolutils-0.2.2.tar.gz
  • Upload date:
  • Size: 624.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for ontolutils-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b52505f77b67ad7a8a15a1f82a2f168101d5bff7ec3fcedfbdcfdd8202f7f14d
MD5 61cb8695a0413f5cafafc2c5d68d8849
BLAKE2b-256 4dfd1b8be277601ae919e100341ccf25d9bd74a7a1302aea2b6f3c6c60a0e2cb

See more details on using hashes here.

File details

Details for the file ontolutils-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ontolutils-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 654.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for ontolutils-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 db46fcc998e3f99b9649d2ecb4b846d75dcfd88ddaf35bf244bce822d998042a
MD5 e137626d347abf4b2330f6739b44ec78
BLAKE2b-256 c233a98eac46b8ea4c777b0628379e2655c2e1495515535b3146a357caa81612

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

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