{"id":6761,"library":"owlrl","title":"OWL-RL","description":"OWL-RL is a Python library that provides a simple implementation of the OWL2 RL Profile, as well as basic RDFS inference, on top of RDFLib. It performs mechanical forward chaining to compute the deductive closure of RDF graphs. The current version is 7.1.4, and it is actively maintained with a focus on semantic web inference capabilities.","status":"active","version":"7.1.4","language":"python","source_language":"en","source_url":"https://github.com/RDFLib/OWL-RL","tags":["RDF","OWL","inference","semantic web","knowledge graph","RDFLib"],"install":[{"cmd":"pip install owlrl","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for RDF graph representation and manipulation, required >=7.1.4.","package":"rdflib","optional":false}],"imports":[{"note":"The module was renamed from RDFClosure to owlrl in version 5.1.0. Ensure you're using the correct module name for newer versions.","wrong":"from RDFClosure import DeductiveClosure","symbol":"DeductiveClosure","correct":"from owlrl import DeductiveClosure"},{"symbol":"RDFS_Semantics","correct":"from owlrl import RDFS_Semantics"},{"symbol":"OWLRL_Semantics","correct":"from owlrl import OWLRL_Semantics"},{"symbol":"Graph","correct":"from rdflib import Graph"}],"quickstart":{"code":"from rdflib import Graph, Literal, Namespace, RDF, RDFS\nfrom owlrl import DeductiveClosure, OWLRL_Semantics\n\n# Define a simple namespace for demonstration\nex = Namespace(\"http://example.org/ontology#\")\n\n# Create an RDFLib graph\ngraph = Graph()\ngraph.bind(\"ex\", ex)\n\n# Add some initial triples (asserted facts)\ngraph.add((ex.Person, RDF.type, RDFS.Class))\ngraph.add((ex.Student, RDFS.subClassOf, ex.Person))\ngraph.add((ex.John, RDF.type, ex.Student))\n\n# Add a rule that says if someone is a Person, they are also an Agent\ngraph.add((ex.Agent, RDF.type, RDFS.Class))\ngraph.add((ex.Person, RDFS.subClassOf, ex.Agent))\n\nprint(f\"Graph size before OWL RL expansion: {len(graph)}\")\n\n# Initialize and run the OWL 2 RL deductive closure\nclosure = DeductiveClosure(OWLRL_Semantics)\nclosure.expand(graph)\n\n# The graph now contains inferred triples, e.g., John is a Person, and also an Agent\nprint(f\"Graph size after OWL RL expansion: {len(graph)}\")\n\n# Check for an inferred triple\nif (ex.John, RDF.type, ex.Agent) in graph:\n    print(\"Inferred: John is an Agent.\")\n\n# You can also run RDFS inference separately\nrdfs_graph = Graph()\nrdfs_graph.bind(\"ex\", ex)\nrdfs_graph.add((ex.Teacher, RDFS.subClassOf, ex.Person))\nrdfs_graph.add((ex.Jane, RDF.type, ex.Teacher))\n\nprint(f\"\\nGraph size before RDFS expansion: {len(rdfs_graph)}\")\nfrom owlrl import RDFS_Semantics\nrdfs_closure = DeductiveClosure(RDFS_Semantics)\nrdfs_closure.expand(rdfs_graph)\nprint(f\"Graph size after RDFS expansion: {len(rdfs_graph)}\")\nif (ex.Jane, RDF.type, ex.Person) in rdfs_graph:\n    print(\"Inferred: Jane is a Person.\")","lang":"python","description":"This quickstart demonstrates how to create an RDFLib graph, populate it with some triples, and then use `owlrl.DeductiveClosure` with `OWLRL_Semantics` or `RDFS_Semantics` to infer new triples based on the respective OWL 2 RL or RDFS rules. The `expand` method modifies the graph in place, adding all possible derived triples. It shows how to check for an inferred triple after expansion."},"warnings":[{"fix":"Upgrade Python to 3.9+ or pin `owlrl` to an older version compatible with your Python environment (e.g., `owlrl<7.0.0` for Python 3.5-3.8, or `owlrl<5.0.0` for Python 2.7).","message":"OWL-RL version 7.x, following RDFLib's dependency updates, now requires Python 3.9 or higher. Older projects using Python 2.7 or earlier Python 3 versions (e.g., 3.5, 3.6) will need to upgrade their Python environment or use an older `owlrl` version.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Update your import statements to use `from owlrl import ...` instead of `from RDFClosure import ...`.","message":"In version 5.1.0, the primary module for the library was renamed from `RDFClosure` to `owlrl`. If you are migrating an older codebase, import statements like `from RDFClosure import DeductiveClosure` must be updated to `from owlrl import DeductiveClosure`.","severity":"breaking","affected_versions":">=5.1.0"},{"fix":"Pre-process your graph to interpret `owl:imports` statements, for example:\n```python\nfrom rdflib import Graph\nfrom owlrl import interpret_owl_imports\n\ng = Graph().parse('my_ontology_with_imports.owl')\ninterpret_owl_imports('auto', g)\n# Now proceed with DeductiveClosure().expand(g)\n```","message":"The `DeductiveClosure` class does not automatically interpret `owl:imports` statements. Any imported ontologies must be explicitly loaded and merged into the graph (e.g., using `owlrl.interpret_owl_imports`) before calling `expand()` for the inference process to consider them.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To use the stricter datatype conversions, call `DeductiveClosure.use_improved_datatypes_conversions()` before expanding graphs, or initialize `DeductiveClosure(improved_datatypes=True)`.\n```python\nfrom owlrl import DeductiveClosure, OWLRL_Semantics\n\nDeductiveClosure.use_improved_datatypes_conversions() # Apply globally\n# or: closure = DeductiveClosure(OWLRL_Semantics, improved_datatypes=True)\n```","message":"RDFLib's default datatype handling may not meet the stricter requirements of OWL 2 RL, potentially leading to incorrect inferences for complex datatypes. `owlrl` provides improved datatype conversion routines, which can be explicitly enabled.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Represent double datatypes in their full lexical form (e.g., `\"1.234E56\"^^xsd:double`) or use a different serialization format if this issue is critical.","message":"A known bug in RDFLib's Turtle parser can cause exceptions when parsing abbreviated double datatypes (e.g., `1.234E56`). It's advisable to avoid this specific literal syntax in your Turtle files if you encounter parsing errors.","severity":"gotcha","affected_versions":"All versions (due to underlying RDFLib issue)"},{"fix":"Avoid using the `convert_graph` entry point if encountering this issue. Ensure your Python environment's `PYTHON_PATH` doesn't lead to ambiguity, or consider upgrading `owlrl` which has renamed scripts to avoid `.py` extensions.","message":"On Windows systems, if both the `owlrl` package and an `owlrl.py` command-line script are present and accessible in `PYTHON_PATH`, attempting to `from owlrl import convert_graph` (an older entry point) could lead to an import collision, as Python might incorrectly try to import from the script file.","severity":"gotcha","affected_versions":"<7.x (likely mitigated by script renaming in newer versions)"}],"env_vars":null,"search_vec":"'7.1.4':48 'activ':52 'basic':24 'capabl':61 'chain':35 'closur':40 'comput':37 'current':45 'deduct':39 'focus':56 'forward':34 'graph':43,68 'implement':15 'infer':26,60,64 'knowledg':67 'librari':10 'maintain':53 'mechan':33 'owl':2,5,63 'owl-rl':1,4 'owl2':18 'perform':32 'profil':20 'provid':12 'python':9 'rdf':42,62 'rdflib':30,69 'rdfs':25 'rl':3,6,19 'semant':58,65 'simpl':14 'top':28 'version':46 'web':59,66 'well':22","created_at":"2026-04-15T18:41:50.514487+00:00","updated_at":"2026-04-16T17:50:30.321223+00:00","problems":[{"fix":"Rename the conflicting `owlrl.py` file to something else (e.g., `my_script.py`) or ensure that `owlrl` is not present in your `PYTHON_PATH` in a way that shadows the installed package.","cause":"This error often occurs on Windows systems when a local script or a file within the virtual environment is named `owlrl.py`, causing Python to try importing `convert_graph` from the script file itself instead of the actual installed `owlrl` package.","error":"cannot import name 'convert_graph' from 'owlrl'"},{"fix":"This is a bug within older `owlrl` command-line scripts (versions 6.x). If you encounter this, either update `owlrl` to a newer version that has fixed this script (if available) or use the `owlrl` library programmatically in Python code, avoiding the command-line script.","cause":"This error happens in `owlrl` versions 6.x when running the command-line utility (e.g., `owlrl --help`). It's due to the `owlrl.py` script attempting to import outdated format constants (like `RDFXML`) that have been removed or moved in newer `rdflib` or `RDFClosure` versions.","error":"ImportError: cannot import name 'RDFXML' from 'RDFClosure.LCC'"},{"fix":"Ensure that your `rdflib` and `owlrl` installations are compatible. This might involve updating both libraries to their latest stable versions, or, if issues persist, checking the `owlrl` GitHub issues for specific `rdflib` version requirements or workarounds.","cause":"This indicates an incompatibility where `owlrl` is trying to reference `OWL.Datatype` from `rdflib`'s OWL namespace, but this specific constant or structure is not present or has changed in the `rdflib` version being used.","error":"owlrl relies on OWL.Datatype which does not exist in the OWL namespace in rdflib"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"7.1.4","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/owlrl/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}