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.

Metadata

Release files for ontolutils 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ontolutils 0.2.2
File Size Uploaded
ontolutils-0.2.2.tar.gz 624.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ontolutils 0.2.2
File Interpreter ABI Platform
ontolutils-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 1.3 MB

Release files / ontolutils-0.2.2.tar.gz

Download URL ontolutils-0.2.2.tar.gz
Size 624.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b52505f77b67ad7a8a15a1f82a2f168101d5bff7ec3fcedfbdcfdd8202f7f14d
BLAKE2b-256 checksum
How to use checksums
4dfd1b8be277601ae919e100341ccf25d9bd74a7a1302aea2b6f3c6c60a0e2cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Release files / ontolutils-0.2.2-py3-none-any.whl

Download URL ontolutils-0.2.2-py3-none-any.whl
Size 654.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db46fcc998e3f99b9649d2ecb4b846d75dcfd88ddaf35bf244bce822d998042a
BLAKE2b-256 checksum
How to use checksums
c233a98eac46b8ea4c777b0628379e2655c2e1495515535b3146a357caa81612
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Release history Release notifications | RSS feed

0.27.5

2 release files

0.27.4

2 release files

0.27.3

2 release files

0.27.2

2 release files

0.27.1

2 release files

0.27.0

2 release files

0.26.0

2 release files

0.25.1

2 release files

0.25.0

2 release files

0.24.1

2 release files

0.24.0

2 release files

0.23.0

2 release files

0.22.1

2 release files

0.22.0

2 release files

0.21.1

2 release files

0.19.3

2 release files

0.19.2

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.15.0

2 release files

0.14.2

2 release files

0.12.4

1 release file

0.12.3

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.23

2 release files

0.2.22

2 release files

0.2.21

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

1 release file

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page