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 and convert between types as needed
  • 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. r4pm-full adds the DuckDB bindings (stream_ocel_to_duckdb, read_consolidated_ocel_from_duckdb, ...), 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 - returns a registry ID
ocel_id = r4pm.import_item('OCEL', 'data/orders.xml')

# Convert to SlimLinkedOCEL for analysis functions
locel_id = bindings.slim_link_ocel(ocel=ocel_id)

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

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

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

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
# Load files into registry
ocel_id = r4pm.import_item('OCEL', 'file.xml')
log_id = r4pm.import_item('EventLog', 'file.xes')

# Convert between types (either like this or using r4pm.convert_item)
locel_id = bindings.index_link_ocel(ocel=ocel_id)
proj_id = bindings.log_to_activity_projection(log=log_id)

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

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 & Alignments

A Petri net is a plain JSON-compatible dict (r4pm.petri_net.PetriNet). Import/export PNML, convert to/from PM4Py, and compute alignment-based fitness with the fast Rust alignment implementation.

import pm4py
import r4pm
from r4pm import petri_net
from r4pm.bindings.conformance.case_centric.alignments import align_variants, compute_fitness

LOG = "test_data/Sepsis Cases - Event Log.xes.gz"

# 1. Discover a Petri net with PM4Py (Inductive Miner infrequent, 0.2 noise threshold)
log = pm4py.read_xes(LOG)
net, im, fm = pm4py.discover_petri_net_inductive(log, noise_threshold=0.2)

# 2. Convert the PM4Py net (+ markings) to an r4pm Petri net dict
rnet = petri_net.from_pm4py(net, im, fm)
# petri_net.export_pnml(rnet, "model.pnml")     # write PNML
# rnet = petri_net.import_pnml("model.pnml")    # or read PNML directly

# 3. Load the log into the registry
log_id = r4pm.import_item("EventLog", LOG)

# 4. Align all variants with the Rust binding and compute fitness
#    (the EventLog id is auto-projected to activity variants)
align_res = align_variants(rnet, log_id)
fitness = compute_fitness(align_res, rnet)
print(fitness)
# {'log_fitness': 0.962, 'average_fitness': 0.907,
#  'perfectly_fitting_frac': 0.626, 'total_costs': 573}

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

# Run comprehensive test suite
python test_all.py

# Run simple example
python example.py

The test suite (test_all.py) covers:

  • Automatic type conversion (positional & keyword arguments)
  • Process discovery (DFG, OC-Declare)
  • Registry operations (CRUD, DataFrames, export)
  • Simple Import/Export DataFrame (df) API
  • Edge cases and conversion caching

LICENSE

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

Metadata

Release files for r4pm 0.6.2

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 0.6.2
File Size Uploaded Provenance Actions
r4pm-0.6.2.tar.gz 70.6 kB With provenance Details for r4pm-0.6.2.tar.gz

Built distributions (wheels)

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

Total release size: 73.2 MB

Release files / r4pm-0.6.2.tar.gz

Download URL r4pm-0.6.2.tar.gz
Size 70.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6161a313130da2e7e84dad8d21f3b5054ecbf78d4085660fe20d22fa3fe2396e
BLAKE2b-256 checksum
How to use checksums
7028309514d739789f16df94d334700bcab361638f8182ce5b11fdf9f737a75c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Release files / r4pm-0.6.2-cp39-abi3-win_amd64.whl

Download URL r4pm-0.6.2-cp39-abi3-win_amd64.whl
Size 11.4 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ebfc5322dbda30bd0fb0f41d1500f1d32ea92f0741ff933c1089cabb71563d35
BLAKE2b-256 checksum
How to use checksums
5024ea9c7d897bfd7803df1391a1e7f6223f6e76a1f89d771151b330593eed38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Release files / r4pm-0.6.2-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL r4pm-0.6.2-cp39-abi3-musllinux_1_2_x86_64.whl
Size 13.5 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
daedb4771b138b1f8b626f9d48183bd050d342c105d1438762694112d8e2c634
BLAKE2b-256 checksum
How to use checksums
491b37d1e659c565b70e8bdc2d8528428b631f83e8bb20ad1ed379c246bfc640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Release files / r4pm-0.6.2-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL r4pm-0.6.2-cp39-abi3-manylinux_2_28_x86_64.whl
Size 12.6 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
4194bab48f638cc2644083bdd0f3a882e6945b6321997612d86241d8975352a2
BLAKE2b-256 checksum
How to use checksums
41ccbcbeedca0329f2b0dda70a16bef6cdb065931cd04e1234698d2b75d66e46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Release files / r4pm-0.6.2-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL r4pm-0.6.2-cp39-abi3-manylinux_2_28_aarch64.whl
Size 12.8 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
36422c38663f90f97972e9d35f80d761812c1e5817cb5fbaca0484dd82fe99be
BLAKE2b-256 checksum
How to use checksums
a1be06168b68e543731168e2be60b22e3fc4154f349fb8231cd4773c8fcd5895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Release files / r4pm-0.6.2-cp39-abi3-macosx_11_0_arm64.whl

Download URL r4pm-0.6.2-cp39-abi3-macosx_11_0_arm64.whl
Size 11.1 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ee094975df3e7dc1c928e8140c747e8d4f986be93b4fa21a6133241af3204eed
BLAKE2b-256 checksum
How to use checksums
63f89a98d79c966ad9469f8910d1ce03988f59e1f43440ade73b9f82ba51a883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Release files / r4pm-0.6.2-cp39-abi3-macosx_10_12_x86_64.whl

Download URL r4pm-0.6.2-cp39-abi3-macosx_10_12_x86_64.whl
Size 11.7 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
78620ef2fe17956df49cf407fc05907c4a9d87a85d8e116c71075bff3d65ff3e
BLAKE2b-256 checksum
How to use checksums
8e18040b3615dba94d2f2c994d9453c7a03dcfc7c519b3263fe166d0f03fcb01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 21, 2026.

Transparency log

Security for r4pm 0.6.2

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-0.6.2.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 Aug 21, 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