{"id":28025,"library":"owlready2","title":"Owlready2","description":"Owlready2 is a Python library for ontology-oriented programming, allowing users to load OWL 2.0 ontologies as Python objects, modify them, save them, and perform reasoning via the HermiT reasoner. It includes an optimized RDF quadstore. Current version is 0.50 (as of latest release) and it follows an irregular release cadence. Requires Python >=3.6.","status":"active","version":"0.50","language":"python","source_language":"en","source_url":"https://github.com/pwin/owlready2","tags":["OWL","ontology","semantic-web","reasoning","RDF","knowledge-graph"],"install":[{"cmd":"pip install owlready2","lang":"bash","label":"Standard installation"}],"dependencies":[],"imports":[{"note":"Importing the module does not automatically expose default_world; use explicit import.","wrong":"import owlready2","symbol":"default_world","correct":"from owlready2 import default_world"},{"note":"","wrong":null,"symbol":"World","correct":"from owlready2 import World"},{"note":"","wrong":null,"symbol":"get_ontology","correct":"from owlready2 import get_ontology"},{"note":"","wrong":null,"symbol":"sync_reasoner","correct":"from owlready2 import sync_reasoner"},{"note":"","wrong":null,"symbol":"Thing","correct":"from owlready2 import Thing"},{"note":"","wrong":null,"symbol":"Property","correct":"from owlready2 import Property"}],"quickstart":{"code":"from owlready2 import get_ontology, sync_reasoner, Thing, Property, default_world\n\n# Load an ontology from a URL or local file\nonto = get_ontology(\"http://www.semanticweb.org/owl/owlapi/tutorial/people.owl\").load()\n\n# Create new classes and properties\nwith onto:\n    class Person(Thing):\n        pass\n    class WorksFor(Property):\n        domain = [Person]\n        range = [Person]\n\n# Create individuals\njohn = Person(\"John\")\nmary = Person(\"Mary\")\njohn.WorksFor = [mary]\n\n# Save ontology\nonto.save()\n\n# Run reasoning\nsync_reasoner()\n\n# Print all individuals\nfor person in onto.Person.instances():\n    print(person.name)","lang":"python","description":"Load an OWL ontology, create classes, individuals, and properties, then run the HermiT reasoner."},"warnings":[{"fix":"Use `world = World()` and `onto = world.get_ontology(...)` instead of relying on the default world.","message":"The default_world is global; modifying it can affect other parts of the program. Use separate World() instances for isolation.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `import owlready2` and `from owlready2 import ...`","message":"Owlready2 changed the import path from the deprecated Owlready (no '2') in older versions. Code using `import owlready` will break.","severity":"breaking","affected_versions":"<0.30"},{"fix":"Always use `with onto: ...` when defining classes or properties.","message":"Modifying ontology entities (e.g., adding properties) must be done inside a `with onto:` block. Otherwise, changes may not persist or cause errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `sync_reasoner_hermit()` instead.","message":"The `sync_reasoner()` function is deprecated in favor of using the HermiT reasoner directly with `sync_reasoner_hermit()`. However, `sync_reasoner()` still works for now.","severity":"deprecated","affected_versions":">=0.50"},{"fix":"Install build tools: on Windows install Microsoft C++ Build Tools; on Linux install g++ and python3-dev.","message":"Installing Owlready2 may fail on some systems due to missing C++ build tools required for the quadstore (cysignals). Ensure you have a C++ compiler installed.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run `pip install owlready2` and use `import owlready2`.","cause":"Owlready2 is not installed, or the wrong import path is used.","error":"ModuleNotFoundError: No module named 'owlready2'"},{"fix":"Use `from owlready2 import default_world`.","cause":"Import was not explicit; `default_world` is not automatically imported with `import owlready2`.","error":"AttributeError: module 'owlready2' has no attribute 'default_world'"},{"fix":"Add `from owlready2 import Thing` to your imports.","cause":"Thing is not imported.","error":"NameError: name 'Thing' is not defined"},{"fix":"Wrap class definitions inside `with onto:`.","cause":"Trying to define classes or properties without the `with onto:` context manager.","error":"Owlready2_OwlException: Cannot define class outside of a `with ontology:` block"},{"fix":"Update to latest version and use `onto.save()`.","cause":"Possibly using an outdated version where save syntax is different.","error":"AttributeError: 'Ontology' object has no attribute 'save' (or similar)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}