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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

r4pm-0.6.1.tar.gz (70.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

r4pm-0.6.1-cp39-abi3-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

r4pm-0.6.1-cp39-abi3-musllinux_1_2_x86_64.whl (13.5 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

r4pm-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl (12.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

r4pm-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl (12.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

r4pm-0.6.1-cp39-abi3-macosx_11_0_arm64.whl (11.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

r4pm-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file r4pm-0.6.1.tar.gz.

File metadata

  • Download URL: r4pm-0.6.1.tar.gz
  • Upload date:
  • Size: 70.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r4pm-0.6.1.tar.gz
Algorithm Hash digest
SHA256 4b3826b47705d4eb6081de599ffa20a6ce83e828576c0f621dc82a44b679daba
MD5 87c8968abac9dea3fc242231e42e3e6d
BLAKE2b-256 8969fe02a8472462d753027cce40ec9f9d4cd8163bfc2a1cd33120d60544d36a

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1.tar.gz:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r4pm-0.6.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: r4pm-0.6.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r4pm-0.6.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5e496754905fcbf96935ecfa59a7a15254de06ef1a19808518348a5359398a47
MD5 a52ff2562913a99320e26f720bb451c4
BLAKE2b-256 af121ed64c1ef0827c4758a3e7f5965ea9e2f5d574164c226e1511bb8ba405f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1-cp39-abi3-win_amd64.whl:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r4pm-0.6.1-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: r4pm-0.6.1-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 13.5 MB
  • Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r4pm-0.6.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5cccb8544a2f4410caf0af442240470933acf558510c92354aa26cfb4c51e5c1
MD5 02207af00f94e15da851ccdaf24327f0
BLAKE2b-256 71ec592a06cf0e6b29252a3395af322ad4429c66bf42031e2e4857c320e94db7

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r4pm-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: r4pm-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 12.6 MB
  • Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r4pm-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6d3a1da5328ee267e53a01bb69a5b1534b8e8dd0a19a1ef0359d4297dcae679
MD5 bf3af7a7aaaf2cba54629ea4c4351b76
BLAKE2b-256 cb992ae753444f754d8003ae1e0c5aa2fc569132baaaa6c98b52825ad491602b

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r4pm-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for r4pm-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e8c6dba30e29200b0699f0c7ddd540663d486b80d55301111a03c11725434df3
MD5 e82ea8e5fef4779cdd877d9cf5d1560d
BLAKE2b-256 d782d94e629e6cf265b2b8ba923ecc066891a9a88610add4adc62dc30a747eef

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r4pm-0.6.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: r4pm-0.6.1-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 11.1 MB
  • Tags: CPython 3.9+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r4pm-0.6.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00e3b818c0c36a890064b88a949cf312956186a828e29d83471ab01d9fab0098
MD5 0046be1bb880b84438ff41b902ac4804
BLAKE2b-256 71a82ba7c3d08dbc81eecd3e315095b1fb6813f894a4f584fef82707dfec67af

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r4pm-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: r4pm-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 11.7 MB
  • Tags: CPython 3.9+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r4pm-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 79f16dbc36934deafa2ffa5d6dd9d17bf090190e372078e067998aa1fe5ddbe6
MD5 35b704bf60c94ba2e4a14da08efc3ba1
BLAKE2b-256 6d91b95aaf268afb90531a27ed173710bf46f1784e8cf4942aae72e7dffe4743

See more details on using hashes here.

Provenance

The following attestation bundles were made for r4pm-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: CI.yml on aarkue/r4pm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.2

7 files

This release

0.6.1 This release

7 files

0.6.0.post1

59 files

0.6.0

52 files

0.5.5

56 files

0.5.4

56 files

0.5.2

56 files

0.5.1

56 files

0.4.4

56 files

0.4.3

50 files

0.4.2

56 files

0.4.0

56 files

0.3.1

56 files

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