Skip to main content

Utility library for the work with ontologies.

Project description

Ontolutils - Object-oriented "Things"

Tests Status Coverage Documentation Status 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:

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:

from pydantic import EmailStr, Field

from ontolutils import Thing, urirefs, namespaces
from pydantic import HttpUrl

@namespaces(prov="http://www.w3.org/ns/prov#",
            foaf="http://xmlns.com/foaf/0.1/")
@urirefs(Person='prov:Person',
         firstName='foaf:firstName',
         last_name='foaf:lastName',
         mbox='foaf:mbox')
class Person(Thing):
    firstName: str
    last_name: str = Field(default=None, alias="lastName")  # you may provide an alias
    mbox: EmailStr = None
    orcidId: HttpUrl = Field(default=None, alias="foaf:orcidId", use_as_id=True)  # use this as ID if available


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:
p.model_dump_jsonld()

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

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

Documentation

Please visit the documentation for more information.

Project details


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.6.0.tar.gz (99.1 kB view details)

Uploaded Source

Built Distribution

ontolutils-0.6.0-py3-none-any.whl (97.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ontolutils-0.6.0.tar.gz
  • Upload date:
  • Size: 99.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.19

File hashes

Hashes for ontolutils-0.6.0.tar.gz
Algorithm Hash digest
SHA256 24c28a1780bab89031032d1524ca12b5522872d4e3c24cb0e5b7d52d431fc2c3
MD5 7891cd6364b2511221cb8adac61cee5b
BLAKE2b-256 2ea14c8355b3ba81dc268d31771d6dbcde29b719c9b289b5ae2fae4ce4ca27ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ontolutils-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 97.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.19

File hashes

Hashes for ontolutils-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 928d06b51c62d4ca9ffcece2568f4d7d79c7c59353f92cedb1f2ccb562506669
MD5 f6720a33e892cbfba76c12487fe24bef
BLAKE2b-256 b553a80569c8f62d9ffa8b782995c37e6da4caf5ff9cc3d0225993687c7a994c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page