Registry / data / owlready2

owlready2

JSON →
library0.50pypypi✓ verified 83d ago

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.

pip install owlready2
INSTALL
IMPORT
SIG · OWLREADY2
O
owlready2
datapythonv0.50
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default_world
from owlready2 import default_world
import owlready2
Importing the module does not automatically expose default_world; use explicit import.
World
from owlready2 import World
get_ontology
from owlready2 import get_ontology
sync_reasoner
from owlready2 import sync_reasoner
Thing
from owlready2 import Thing
Property
from owlready2 import Property

Load an OWL ontology, create classes, individuals, and properties, then run the HermiT reasoner.

from owlready2 import get_ontology, sync_reasoner, Thing, Property, default_world # Load an ontology from a URL or local file onto = get_ontology("http://www.semanticweb.org/owl/owlapi/tutorial/people.owl").load() # Create new classes and properties with onto: class Person(Thing): pass class WorksFor(Property): domain = [Person] range = [Person] # Create individuals john = Person("John") mary = Person("Mary") john.WorksFor = [mary] # Save ontology onto.save() # Run reasoning sync_reasoner() # Print all individuals for person in onto.Person.instances(): print(person.name)
Debug
Known issues
gotchaThe default_world is global; modifying it can affect other parts of the program. Use separate World() instances for isolation.
fix
Use `world = World()` and `onto = world.get_ontology(...)` instead of relying on the default world.
affects: all
breakingOwlready2 changed the import path from the deprecated Owlready (no '2') in older versions. Code using `import owlready` will break.
fix
Use `import owlready2` and `from owlready2 import ...`
affects: <0.30
gotchaModifying ontology entities (e.g., adding properties) must be done inside a `with onto:` block. Otherwise, changes may not persist or cause errors.
fix
Always use `with onto: ...` when defining classes or properties.
affects: all
deprecatedThe `sync_reasoner()` function is deprecated in favor of using the HermiT reasoner directly with `sync_reasoner_hermit()`. However, `sync_reasoner()` still works for now.
fix
Use `sync_reasoner_hermit()` instead.
affects: >=0.50
gotchaInstalling Owlready2 may fail on some systems due to missing C++ build tools required for the quadstore (cysignals). Ensure you have a C++ compiler installed.
fix
Install build tools: on Windows install Microsoft C++ Build Tools; on Linux install g++ and python3-dev.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'owlready2'
Owlready2 is not installed, or the wrong import path is used.
fix
Run `pip install owlready2` and use `import owlready2`.
AttributeError: module 'owlready2' has no attribute 'default_world'
Import was not explicit; `default_world` is not automatically imported with `import owlready2`.
fix
Use `from owlready2 import default_world`.
NameError: name 'Thing' is not defined
Thing is not imported.
fix
Add `from owlready2 import Thing` to your imports.
Owlready2_OwlException: Cannot define class outside of a `with ontology:` block
Trying to define classes or properties without the `with onto:` context manager.
fix
Wrap class definitions inside `with onto:`.
AttributeError: 'Ontology' object has no attribute 'save' (or similar)
Possibly using an outdated version where save syntax is different.
fix
Update to latest version and use `onto.save()`.
Upgrade
Version history
0.50latest on PyPI · released Feb 5, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
owlready2 — pip install owlready2 · libregistry