Skip to main content
Rust4PM

Use Rust4PM with PM4Py

Read event data with Rust4PM and analyze it with PM4Py, using DataFrames and PM4Py's own OCEL objects.

PM4Py is a process mining library for Python with a large set of algorithms. Rust4PM's importers and exporters are written in Rust, so a common setup is Rust4PM for reading and writing files and PM4Py for algorithms that Rust4PM does not have.

pip install "r4pm[polars]" pm4py
python
import pm4py
import r4pm

# Rust4PM reads the log (fast), PM4Py analyzes it.
df, log_attributes = r4pm.df.import_xes("data/road-traffic-fines.xes.gz")
events = df.to_pandas()
print(len(events), "events")

dfg, start_activities, end_activities = pm4py.discover_dfg(events)
print(len(dfg), "directly-follows edges")

# OCEL 2.0 straight into PM4Py's OCEL object.
ocel = r4pm.df.import_ocel_pm4py("data/order-management.xml.gz")
print(ocel.get_summary().splitlines()[0])
output
561470 events
70 directly-follows edges
Object-Centric Event Log (number of events: 21008, number of objects: 10840, number of activities: 11, number of object types: 6, events-objects relationships: 147463)

PM4Py also prints a license notice when it is imported.

The r4pm.df module

r4pm.df reads and writes event data as polars DataFrames, with the standard XES column names (case:concept:name, concept:name, time:timestamp) that PM4Py expects:

FunctionWhat it does
import_xes(path)A DataFrame with one row per event, plus the log attributes as JSON
export_xes(df, path)Write a DataFrame back to XES
import_ocel(path)An OCEL 2.0 file as a dict of DataFrames
import_ocel_pm4py(path)An OCEL 2.0 file as a PM4Py OCEL object
export_ocel(tables, path)Write the dict of DataFrames back to an OCEL 2.0 file

Call .to_pandas() on a polars DataFrame for libraries that expect pandas.

Petri nets

r4pm.petri_net.to_pm4py(net) turns a Petri net from Rust4PM (e.g., from Alpha+++) into PM4Py's (net, initial_marking, final_marking), and from_pm4py converts the other way. With that, you can discover in Rust4PM and visualize or check conformance in PM4Py, or the reverse.