CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pm4py

Process mining library for discovering, analyzing and visualizing business processes from event data

Pending
Overview
Eval results
Files

reading-writing.mddocs/

Reading and Writing Operations

Comprehensive I/O operations for process mining data formats. PM4PY supports traditional event logs, process models, and Object-Centric Event Logs (OCEL) with various file formats and encoding options.

Capabilities

XES Event Log I/O

Read and write event logs in the XES (eXtensible Event Stream) standard format, supporting multiple parser variants and encoding options.

def read_xes(file_path, variant=None, return_legacy_log_object=False, encoding='utf-8', **kwargs):
    """
    Read XES event log files.
    
    Parameters:
    - file_path (str): Path/URI to XES file
    - variant (Optional[str]): Parser variant ('iterparse', 'line_by_line', 'chunk_regex', 'rustxes')
    - return_legacy_log_object (bool): Whether to return EventLog object vs DataFrame
    - encoding (str): File encoding (default: 'utf-8')
    
    Returns:
    Union[DataFrame, EventLog]: Event log data
    """

def write_xes(log, file_path, case_id_key='case:concept:name', extensions=None, encoding='utf-8', variant_str=None, **kwargs):
    """
    Write event logs to XES format.
    
    Parameters:
    - log (Union[EventLog, pd.DataFrame]): Event log to write
    - file_path (str): Target file path
    - case_id_key (str): Case identifier column
    - extensions (Optional[List]): XES extensions to include
    - encoding (str): File encoding
    
    Returns:
    None
    """

Process Model I/O

Read and write various process model formats including Petri nets (PNML), process trees (PTML), and BPMN models.

def read_pnml(file_path, auto_guess_final_marking=False, encoding='utf-8'):
    """
    Read Petri net models from PNML files.
    
    Parameters:
    - file_path (str): Path to PNML file
    - auto_guess_final_marking (bool): Auto-detect final marking
    - encoding (str): File encoding
    
    Returns:
    Tuple[PetriNet, Marking, Marking]: (petri_net, initial_marking, final_marking)
    """

def write_pnml(petri_net, initial_marking, final_marking, file_path, encoding='utf-8'):
    """
    Write Petri nets to PNML format.
    
    Parameters:
    - petri_net (PetriNet): Petri net model
    - initial_marking (Marking): Initial marking
    - final_marking (Marking): Final marking
    - file_path (str): Target file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

def read_ptml(file_path, encoding='utf-8'):
    """
    Read process tree models from PTML files.
    
    Parameters:
    - file_path (str): Path to PTML file
    - encoding (str): File encoding
    
    Returns:
    ProcessTree: Process tree model
    """

def write_ptml(tree, file_path, auto_layout=True, encoding='utf-8'):
    """
    Write process trees to PTML format.
    
    Parameters:
    - tree (ProcessTree): Process tree model
    - file_path (str): Target file path
    - auto_layout (bool): Apply automatic layout
    - encoding (str): File encoding
    
    Returns:
    None
    """

BPMN Model I/O

Read and write Business Process Model and Notation (BPMN) files with layout support.

def read_bpmn(file_path, encoding='utf-8'):
    """
    Read BPMN models from BPMN files.
    
    Parameters:
    - file_path (str): Path to BPMN file
    - encoding (str): File encoding
    
    Returns:
    BPMN: BPMN model object
    """

def write_bpmn(model, file_path, auto_layout=True, encoding='utf-8'):
    """
    Write BPMN models to file.
    
    Parameters:
    - model (BPMN): BPMN model to write
    - file_path (str): Target file path
    - auto_layout (bool): Apply automatic layout
    - encoding (str): File encoding
    
    Returns:
    None
    """

Directly-Follows Graph I/O

Read and write Directly-Follows Graphs (DFGs) which represent direct successor relationships between activities.

def read_dfg(file_path, encoding='utf-8'):
    """
    Read Directly-Follows Graphs from DFG files.
    
    Parameters:
    - file_path (str): Path to DFG file
    - encoding (str): File encoding
    
    Returns:
    Tuple[Dict[Tuple[str, str], int], Dict[str, int], Dict[str, int]]: 
        (dfg_dict, start_activities, end_activities)
    """

def write_dfg(dfg, start_activities, end_activities, file_path, encoding='utf-8'):
    """
    Write DFGs to file.
    
    Parameters:
    - dfg (Dict[Tuple[str, str], int]): DFG dictionary
    - start_activities (Dict[str, int]): Start activities and frequencies
    - end_activities (Dict[str, int]): End activities and frequencies
    - file_path (str): Target file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

OCEL 1.0 I/O

Read and write Object-Centric Event Logs in various formats (CSV, JSON, XML, SQLite) with automatic format detection.

def read_ocel(file_path, objects_path=None, encoding='utf-8'):
    """
    Read object-centric event logs (auto-detects format).
    
    Parameters:
    - file_path (str): Path to OCEL file
    - objects_path (Optional[str]): Path to objects file (for CSV format)
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel_csv(file_path, objects_path=None, encoding='utf-8'):
    """
    Read OCEL from CSV format.
    
    Parameters:
    - file_path (str): Path to events CSV file
    - objects_path (Optional[str]): Path to objects CSV file
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel_xml(file_path, encoding='utf-8'):
    """
    Read OCEL from XML format.
    
    Parameters:
    - file_path (str): Path to OCEL XML file
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel_json(file_path, encoding='utf-8'):
    """
    Read OCEL from JSON format.
    
    Parameters:
    - file_path (str): Path to OCEL JSON file
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel_sqlite(file_path, encoding='utf-8'):
    """
    Read OCEL from SQLite database.
    
    Parameters:
    - file_path (str): Path to SQLite database file
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

OCEL 1.0 Writing

Write Object-Centric Event Logs in multiple formats with consistent interface.

def write_ocel(ocel, file_path, objects_path=None, encoding='utf-8'):
    """
    Write OCEL to various formats (CSV, JSON, XML, SQLite).
    Format determined by file extension.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target file path
    - objects_path (Optional[str]): Path for objects file (CSV format)
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel_csv(ocel, file_path, objects_path, encoding='utf-8'):
    """
    Write OCEL to CSV format.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Path for events CSV file
    - objects_path (str): Path for objects CSV file
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel_json(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL to JSON format.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target JSON file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel_xml(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL to XML format.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target XML file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel_sqlite(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL to SQLite database.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target SQLite database path
    - encoding (str): File encoding
    
    Returns:
    None
    """

OCEL 2.0 I/O

Read and write the next generation OCEL 2.0 format with enhanced capabilities and performance.

def read_ocel2(file_path, variant_str=None, encoding='utf-8'):
    """
    Read OCEL 2.0 format (auto-detects format).
    
    Parameters:
    - file_path (str): Path to OCEL 2.0 file
    - variant_str (Optional[str]): Specific variant to use
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel2_sqlite(file_path, variant_str=None, encoding='utf-8'):
    """
    Read OCEL 2.0 from SQLite.
    
    Parameters:
    - file_path (str): Path to SQLite database
    - variant_str (Optional[str]): Specific variant to use
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel2_json(file_path, encoding='utf-8'):
    """
    Read OCEL 2.0 from JSON.
    
    Parameters:
    - file_path (str): Path to JSON file
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def read_ocel2_xml(file_path, encoding='utf-8'):
    """
    Read OCEL 2.0 from XML.
    
    Parameters:
    - file_path (str): Path to XML file
    - encoding (str): File encoding
    
    Returns:
    OCEL: Object-centric event log
    """

def write_ocel2(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL 2.0 format.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel2_sqlite(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL 2.0 to SQLite.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target SQLite database path
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel2_xml(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL 2.0 to XML.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target XML file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

def write_ocel2_json(ocel, file_path, encoding='utf-8'):
    """
    Write OCEL 2.0 to JSON.
    
    Parameters:
    - ocel (OCEL): Object-centric event log
    - file_path (str): Target JSON file path
    - encoding (str): File encoding
    
    Returns:
    None
    """

Usage Examples

Basic Event Log Reading

import pm4py

# Read XES file
log = pm4py.read_xes('event_log.xes')

# Read with specific parser variant for large files
log = pm4py.read_xes('large_log.xes', variant='rustxes')

# Return as DataFrame instead of EventLog object
df = pm4py.read_xes('event_log.xes', return_legacy_log_object=False)

Process Model I/O

import pm4py

# Read Petri net
net, initial_marking, final_marking = pm4py.read_pnml('model.pnml')

# Read process tree
tree = pm4py.read_ptml('process_tree.ptml')

# Write models
pm4py.write_pnml(net, initial_marking, final_marking, 'output_model.pnml')
pm4py.write_ptml(tree, 'output_tree.ptml')

OCEL I/O Operations

import pm4py

# Read OCEL (auto-detect format)
ocel = pm4py.read_ocel('ocel_data.csv', objects_path='objects.csv')
ocel = pm4py.read_ocel('ocel_data.json')

# Read OCEL 2.0
ocel2 = pm4py.read_ocel2('ocel2_data.sqlite')

# Write OCEL in different formats
pm4py.write_ocel_json(ocel, 'output.json')
pm4py.write_ocel_sqlite(ocel, 'output.sqlite')
pm4py.write_ocel2(ocel, 'output_v2.sqlite')

Install with Tessl CLI

npx tessl i tessl/pypi-pm4py

docs

conformance-checking.md

filtering.md

index.md

ml-organizational.md

object-centric.md

process-discovery.md

reading-writing.md

statistics-analysis.md

utilities-conversion.md

visualization.md

tile.json