Skip to main content

r4pm

Python bindings for the Rust4PM Project: Process mining in Python with the speed of Rust

This library provides basic import/export of XES/OCEL event data, as well as other exposed functionality from the Rust4PM project (e.g., process discovery algorithms).

Features

  • Fast XES/OCEL Import/Export: Efficient Rust-based import and export of .xes, .xes.gz, and OCEL2 (.xml/.json) files
  • Auto-Generated Bindings: All process_mining functions automatically exposed with full IDE support (autocomplete, type hints, docs)
  • Registry System: Manage data objects as typed handles and convert between types as needed
  • Conformance Checking: Alignments, fitness and precision on pm4py or r4pm logs and Petri nets
  • Polars DataFrames: Polars facilitates the fast transfer of event data from Python to Rust and vice versa

Installation

pip install r4pm         # default
pip install r4pm-full    # additionally bundles DuckDB (~15 MiB larger)

Both provide the r4pm import package, so install one or the other. pip install r4pm[pm4py] adds pm4py for the pm4py interoperability, pip install r4pm[progress] adds tqdm for progress bars. r4pm-full adds the DuckDB bindings (write_ocel_to_duckdb, stream_ocel_file_to_duckdb, ...) and .duckdb import and export, nothing else differs.

import r4pm

r4pm.__variant__                 # "default" or "full"
r4pm.__features__                # optional features compiled in
r4pm.has_feature("ocel-duckdb")

Quick Start

from r4pm import bindings
import r4pm

# Load an OCEL file into the registry; returns a handle (also usable as the item's ID)
ocel = r4pm.import_item('OCEL', 'data/orders.xml')

# Bindings convert an item to the type they take (most take a SlimLinkedOCEL); convert once
# when calling several of them
locel = ocel.convert('SlimLinkedOCEL')

# Get statistics
num = bindings.num_events(ocel=locel)
print(f"Events: {num}")

# Discover object-centric DFG
dfg = bindings.discover_ocdfg(locel)
print(f"Discovered DFG for {len(dfg['object_type_to_dfg'])} object types")

# For case-centric event logs:
log = r4pm.import_item('EventLog', 'data/log.xes')
case_dfg = bindings.discover_dfg(log)

How It Works

Auto-Generated Bindings

All functions from the process_mining Rust library are automatically discovered and exposed as Python functions with:

  • Full type hints for IDE autocomplete
  • Automatic documentation from Rust docs
  • Type validation via JSON schemas

The bindings are organized by module (mirroring the Rust crate structure):

from r4pm import bindings

# Top-level access to all functions
bindings.discover_dfg(event_log=log_id)
bindings.num_events(ocel=locel_id)

# Or use submodules for organization
from r4pm.bindings.discovery.case_centric import dfg
dfg.discover_dfg(event_log=log_id)

Bindings are automatically generated during the Rust build via build.rs.

Registry System

Data is managed through a registry that holds different object types:

  • OCEL - Raw OCEL data
  • SlimLinkedOCEL - Memory-efficient linked OCEL (required by most functions)
  • IndexLinkedOCEL - Indexed OCEL for analysis
  • EventLog - Case-centric event log
  • EventLogActivityProjection - Activity-projected log for discovery
  • PetriNet, AcceptingPetriNet, ProcessTree, ObjectCentricPetriNet, OCDeclareModel - Process models

Registry items are returned as handles (r4pm.handles), typed by kind (handles.OCEL, handles.EventLog, ...). A handle is a str subclass holding the item's ID, so it works wherever an ID is accepted. A handle returned by r4pm owns its item: the item is removed when the handle is closed, leaves a with block, or is garbage collected. Items created with an explicit ID (item_id=..., output_id=...) stay until removed with r4pm.remove_item.

# Load files into the registry
ocel = r4pm.import_item('OCEL', 'file.xml')
log = r4pm.import_item('EventLog', 'file.xes')

# Convert between types (either like this or using r4pm.convert_item)
locel = ocel.convert('IndexLinkedOCEL')
proj = log.convert('EventLogActivityProjection')

with r4pm.import_item('AcceptingPetriNet', 'model.pnml') as net:
    print(net.kind, net.to_json()["transitions"][0])
# net is removed from the registry here

# List registry contents
for item in r4pm.list_items():
    print(f"{item['id']}: {item['type']}")

Arguments that take a registry item also accept a path to a file, which is loaded only for that call. Bindings that change an item in place (e.g., locel_add_event) need a stored item instead. Failed calls raise r4pm.BindingError.

A binding that returns a value and also produces an item, like extraction_run, takes a required output_id. It stores the item under that ID and returns the value (here the ExtractionReport).

Progress and cancellation

Long-running bindings report their progress. r4pm.set_progress shows it for every binding call, and the progress= argument of each binding overrides that for one call:

r4pm.set_progress("tqdm")      # one tqdm bar per stage (pip install r4pm[progress])
r4pm.set_progress(lambda stage, done, total: print(stage, done, total))  # total may be None
r4pm.set_progress(None)        # the default: no progress display

bindings.discover_oc_declare(locel, progress="tqdm")
bindings.discover_oc_declare(locel, progress=False)  # nothing for this call

Ctrl+C cancels a running binding, and so does an exception raised by the progress callback. The call stops at the next cancellation check of the binding and stores nothing, then the KeyboardInterrupt (or the callback's exception) is raised. A binding that never checks runs to the end first. Warnings of a binding (e.g., skipped rows in an import) become Python UserWarnings.

r4pm.import_item and r4pm.df.import_ocel (with its _xml/_json/_pm4py variants) work the same way: they take progress= (for most file formats, stage "Importing" with the bytes read), and a cancelled import_item adds nothing to the registry.

Simple Import/Export API

For direct DataFrame operations without the registry, use the df submodule.

XES

import r4pm

# Import returns (DataFrame, log_attributes_json)
xes, attrs = r4pm.df.import_xes("file.xes", date_format="%Y-%m-%d")
r4pm.df.export_xes(xes, "test_data/output.xes")

OCEL

# Returns dict with DataFrames: events, objects, relations, o2o, object_changes
ocel = r4pm.df.import_ocel("file.xml")
print(ocel['events'].shape)
r4pm.df.export_ocel(ocel, "export.xml")

# PM4Py integration (requires pm4py)
ocel_pm4py = r4pm.df.import_ocel_pm4py("file.xml")
print(ocel['events'].shape)
r4pm.df.export_ocel_pm4py(ocel_pm4py, "export.xml")

Petri Nets

A Petri net is a JSON-compatible dict (r4pm.petri_net.PetriNet) with places and transitions in lists, identified by index. Each transition lists its input and output arcs as [place index, weight], a silent transition has label None, and markings map place indices to token counts:

from r4pm import petri_net

net = petri_net.import_pnml("model.pnml")
# {'places': [{'name': 'source'}, {'name': 'sink'}],
#  'transitions': [{'label': 'a', 'name': 't1', 'inputs': [[0, 1]], 'outputs': [[1, 1]]}],
#  'initial_marking': {'0': 1}, 'final_marking': {'1': 1}}
petri_net.export_pnml(net, "copy.pnml")

pm4py_net, im, fm = petri_net.to_pm4py(net)        # and back with petri_net.from_pm4py
handle = petri_net.to_handle(net)                  # keep it in the registry

Conformance Checking

r4pm.conformance computes alignments, fitness and precision with the Rust implementation. Logs can be pm4py EventLogs, pandas or polars DataFrames (pm4py column names), r4pm handles, XES paths, or lists of activity sequences. Nets can be pm4py nets with markings, Petri net dicts, handles, or PNML paths.

With pm4py objects, the results have pm4py's shape:

import pm4py
from r4pm import conformance

log = pm4py.read_xes("log.xes")
net, im, fm = pm4py.discover_petri_net_inductive(log, noise_threshold=0.2)

conformance.fitness(log, net, im, fm)
# {'log_fitness': 0.962, 'average_trace_fitness': 0.907, 'percentage_of_fitting_traces': 62.6, ...}
conformance.precision(log, net, im, fm, preset="pm4py")   # as pm4py.precision_alignments

aligned = conformance.alignments(log, net, im, fm)          # one per trace, as pm4py
aligned[0]["alignment"]   # [('A', 'A'), ('>>', None), ('B', '>>'), ...]
conformance.precision(aligned)                              # reuses the alignments

With r4pm objects, nothing passes through Python but the result:

import r4pm
from r4pm import bindings, conformance
from r4pm.conformance import AlignmentOptions

log = r4pm.import_item("EventLog", "log.xes")
net = bindings.discover_inductive_net(log)    # Petri net dict

conformance.fitness(log, net)
conformance.fitness(log, net, method="token_based")    # nets without silent transitions
conformance.precision(log, "model.pnml", preset="prom")
conformance.precision_result(log, net, report_escaping_edges=True)

options = AlignmentOptions(log_move_cost=2, max_states=1_000_000, max_memory_mib=4096)
aligned = conformance.alignments(log, net, options=options, num_threads=4)
for variant in aligned.variants:                   # typed, one per trace variant
    print(variant.frequency, variant.fitness, [m.kind for m in variant.moves or []])

Precision presets: "default" (paths from optimal alignments), "prom" (ProM's "Check Precision using Escaping Edges") and "pm4py" (as pm4py.precision_alignments).

r4pm.interop converts event logs between pm4py and the registry (log_from_pm4py, log_to_pm4py), and Petri nets (net_from_pm4py, net_to_pm4py).

Reflow

Reflow decides which object types flow through each activity, so discovery runs on a smaller log. It is available through the generated bindings:

import r4pm
from r4pm import bindings

with r4pm.import_item("OCEL", "order-management.json") as ocel:
    slim = ocel.convert("SlimLinkedOCEL")
    result = bindings.reflow(slim)                     # flow layer and cell states
    flow = bindings.reflow_flow_projection(bindings.reflow_tag(slim, result))
    model = bindings.reflow_annotated_ocpn(slim, result)
    svg = bindings.reflow_annotated_ocpn_svg(model)    # show in Jupyter with IPython.display.SVG

reflow_tag returns the log with non-flow participations marked by the qualifier prefix !, readable by any OCEL 2.0 tool; reflow_flow_projection keeps only the flowing ones.

Examples

examples/ holds short scripts that check their own results: progress.py (progress, cancellation, warnings) and extraction.py (OCEL extraction from SQLite with a blueprint). Run one with python examples/progress.py. pytest tests/test_examples.py runs all of them.

Development

Setup

# Install Rust: https://rustup.rs/
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install in development mode
pip install maturin
maturin develop --release

How Bindings Are Generated

Python bindings are automatically generated during the Rust build via build.rs. Thus, bindings are always in sync with the Rust code and do not require manual regeneration.

The build script:

  1. Reads function metadata from the process_mining crate
  2. Generates r4pm/bindings/ with typed Python wrappers and .pyi stubs
  3. Organizes functions by their Rust module structure

Building for Release

maturin build --release  # Creates wheels in target/wheels/

The wheel automatically includes the generated bindings.

Running Tests

pip install pytest pm4py polars pandas pyarrow
maturin develop
pytest

The test suite (tests/) covers conformance checking against pm4py (alignment fitness, per-trace alignments, precision, token-based replay), the input and output forms, registry handles, Petri net conversion, and the generated bindings and stubs.

LICENSE

This package is licensed under either Apache License Version 2.0 or MIT License at your option.

Metadata

Release files for r4pm-full 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for r4pm-full 0.7.1
File Size Uploaded Provenance Actions
r4pm_full-0.7.1.tar.gz 115.6 kB With provenance Details for r4pm_full-0.7.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for r4pm-full 0.7.1
File Actions
r4pm_full-0.7.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for r4pm_full-0.7.1-cp39-abi3-win_amd64.whl
r4pm_full-0.7.1-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for r4pm_full-0.7.1-cp39-abi3-musllinux_1_2_x86_64.whl
r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_x86_64.whl
r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_aarch64.whl
r4pm_full-0.7.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for r4pm_full-0.7.1-cp39-abi3-macosx_11_0_arm64.whl
r4pm_full-0.7.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for r4pm_full-0.7.1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 183.6 MB

Release files / r4pm_full-0.7.1.tar.gz

Download URL r4pm_full-0.7.1.tar.gz
Size 115.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ccb9f8d1add89f3dc89cf2146cd899144829f93bf731923e608d027e81c152b5
BLAKE2b-256 checksum
How to use checksums
18c8b1c7482b9f80765c693d5f543db992aae6c247dc05a879f7427cf6d4356e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / r4pm_full-0.7.1-cp39-abi3-win_amd64.whl

Download URL r4pm_full-0.7.1-cp39-abi3-win_amd64.whl
Size 24.9 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
74a04c234afbe1d95cb3f0697466f78baa6ba9663410b1e66342c1ea2f821e8a
BLAKE2b-256 checksum
How to use checksums
5fab09e7d368ce7ab4dca78234cb956ec9bf6213923bb5456e1f602925b66418
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / r4pm_full-0.7.1-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL r4pm_full-0.7.1-cp39-abi3-musllinux_1_2_x86_64.whl
Size 39.9 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
881b7be985175f6bd5d5d240738ba0d057145cf0a42c9e7add774a782a6d1b97
BLAKE2b-256 checksum
How to use checksums
192c2140b699ff259dd11321852e513b2a339220d2b9cad3e3a5a655df0022ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_x86_64.whl
Size 32.0 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
2693807514f3d843c0cbdd1846e7d66572f72463b07e619bcc7f0d77772e697f
BLAKE2b-256 checksum
How to use checksums
fed62f5d2122fb1a8709b0f0afd0c537d7ba056345374438b9735744ec589517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL r4pm_full-0.7.1-cp39-abi3-manylinux_2_28_aarch64.whl
Size 31.4 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
fe653081c674aa5a2e77eaa1261f73e37e2532224e23b15845303dc9ca38b384
BLAKE2b-256 checksum
How to use checksums
2a7faf4a6531ce14e686dbca7f13c570a2dbdd99192f28180785be2b83af8380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / r4pm_full-0.7.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL r4pm_full-0.7.1-cp39-abi3-macosx_11_0_arm64.whl
Size 27.0 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a7dd112effd8cafccaba83322e6e1b1f9106893adfb284c9ad1e90d936ed3348
BLAKE2b-256 checksum
How to use checksums
d60913c8c0ef13a94144bbb66b5a80052a62378ee6ae77297dd46c17f1e5ca26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / r4pm_full-0.7.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL r4pm_full-0.7.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 28.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e0292123147e8c7b0402e20c2b5795b1c4beee4ead4a02238706dcc0850f4999
BLAKE2b-256 checksum
How to use checksums
43724c1b70103ee5cdf57f51913d1225326cf0faefc30f8495ad73fe267607b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for r4pm-full 0.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for r4pm_full-0.7.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page