In some use cases, OCEL logs contain more information than is specified in the OCEL 2.0 standard. To support these cases in a standardized and portable way, Ocelescope provides OCEL extensions.
Extensions allow you to add custom data to OCEL logs and store or load that data alongside the main event and object logs.
To define an extension, create a class that inherits from OCELExtension (provided by the ocelescope package). This class defines how the extension is detected, imported, and exported.
Each extension must define the following attributes and methods:
name: A short identifier for the extension
description: A human-readable explanation of what the extension adds
version: The extension’s version
supported_extensions: A list of file types the extension supports (e.g., [".xmlocel"])
The class must also implement three key methods:
has_extension(path: Path) -> bool Checks if the extension is present at the given file path
import_extension(ocel: OCEL, path: Path) -> OCELExtension Loads the extension data from the path and returns an instance
export_extension(path: Path) -> None Saves the extension data to the path
fromabcimportABC,abstractmethodfrompathlibimportPathfromtypingimportTypeVarfromocelescope.ocel.constantsimportOCELFileExtensionsT=TypeVar("T",bound="OCELExtension")classOCELExtension(ABC):""" Abstract base class for OCEL extensions that can be imported/exported from a file path. """name:strdescription:strversion:strsupported_extensions:list[OCELFileExtensions]@staticmethod@abstractmethoddefhas_extension(path:Path)->bool:pass@classmethod@abstractmethoddefimport_extension(cls:type[T],ocel:"OCEL",path:Path)->T:pass@abstractmethoddefexport_extension(self,path:Path)->None:pass
This version of the HelloWorldExtension stores a message directly inside the .jsonocel file under a custom top-level field like "hello_message". It only loads if that field is present.
importjsonfrompathlibimportPathfromocelescopeimportOCEL,OCELExtensionclassHelloWorldExtension(OCELExtension):name="HelloWorld"description="Stores a simple message string in the .jsonocel file"version="1.0"supported_extensions=[".jsonocel"]def__init__(self,ocel:OCEL,message:str="Hello from extension!"):self.ocel=ocelself.message=message@staticmethoddefhas_extension(path:Path)->bool:ifpath.suffix!=".jsonocel":returnFalsetry:withopen(path,"r",encoding="utf-8")asf:data=json.load(f)return"hello_message"indataexceptException:returnFalse@classmethoddefimport_extension(cls,ocel:OCEL,path:Path)->"HelloWorldExtension":withopen(path,"r",encoding="utf-8")asf:data=json.load(f)message=data.get("hello_message","No message found.")returncls(ocel,message=message)defexport_extension(self,path:Path)->None:try:withopen(path,"r",encoding="utf-8")asf:data=json.load(f)exceptException:data={}data["hello_message"]=self.messagewithopen(path,"w",encoding="utf-8")asf:json.dump(data,f,indent=2)