DEV Community

loading...
Cover image for Python tools for the semantic web

Python tools for the semantic web

SeriousFun01
serious fun!
Updated on ・3 min read

The Semantic Web still needs introductions

The term Semantic Web refers to W3C’s vision of the Web of linked data. Semantic Web technologies enable people to create data stores on the Web, build vocabularies, and write rules for handling data. Linked data are empowered by technologies such as RDF, SPARQL, OWL, and SKOS.

The Semantic Web and its acronyms have a habit of sounding frightening: From ontologies to reification, from predicates to reasoners and open world assumptions it is full with arcane words and concepts. Its not clear if that is a bug or a feature (academics wanting to sound important).

These concepts are by now quite old but for most web application developers they probably still don't mean anything concrete. Yet is is not that the current set of preferred tools and API's for exchanging data on the web (HTML/CSS, JSON, REST, GRAPHQL etc.) are adequate for building an global web of data that can handle the enormous complexity and variability of our data universes.

The problems that the semantic web promises to solve are quite real, but for a combination of reasons that need some deeper research to uncover and properly rank, adoption has been rather niche.

The past, though, might not be a good predictor of the future:

The bottom line is that the global interconnected web needs a systematic way to communicate metadata about data and this is what the Semantic Web really does (and not other technology is really available for this)

Python needs no introductions

One interesting development in recent years has been the rise of Python as enabling technology that lowers the barrier of entry for people to pursue a range of information technology tasks,from datascience to web development.

Can Python help bring the concepts of the Semantic Web closer to broader communities of developers? I don't know but it will be interesting to see.

Without further ado, a list of Semantic Web Python tools that lower the barrier of entry to the semantic web (feel free to add in comments others that I might have missed)

RDFlib

RDFLib is a pure Python package for working with RDF. RDFLib contains most things you need to work with RDF, including:

  • parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, Trig and JSON-LD (via a plugin).
  • a Graph interface which can be backed by any one of a number of Store implementations
  • store implementations for in-memory storage and persistent storage on top of the Berkeley DB
  • a SPARQL 1.1 implementation - supporting SPARQL 1.1 Queries and Update statements

Importantly, rdflib has a json-ld plugin that helps bridge the JSON world with the Semantic Web world

owlready

Owlready2 is a package for ontology-oriented programming in Python. It can load OWL 2.0 ontologies as Python objects, modify them, save them, and perform reasoning via HermiT (included). Owlready2 allows a transparent access to OWL ontologies (contrary to usual Java-based API's).

pySHACL

pySHACL is a pure Python module which allows for the validation of RDF graphs against Shapes Constraint Language (SHACL) graphs. It is built on top of rdflib.

Shapes Constraint Language (SHACL) is data validation on steroids: It is a World Wide Web Consortium (W3C) specification for validating graph-based data against a set of conditions. Among others, SHACL includes features to express conditions that constrain the number of values that a property may have, the type of such values, numeric ranges, string matching patterns, and logical combinations of such constraints.

ontospy

ontospy expresses the statement seeing is believing :-). It is a Python library and command-line interface for inspecting and visualizing RDF models.

See for example this beautiful visualization of schema.org

Discussion (0)

Forem Open with the Forem app