Skip to main content

Rust-based Process Mining

Project description

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

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")

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.

Project details


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.5.5a1.tar.gz (79.6 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.5.5a1-cp314-cp314-win_amd64.whl (9.2 MB view details)

Uploaded CPython 3.14Windows x86-64

r4pm-0.5.5a1-cp314-cp314-manylinux_2_28_x86_64.whl (42.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

r4pm-0.5.5a1-cp314-cp314-macosx_11_0_arm64.whl (9.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

r4pm-0.5.5a1-cp314-cp314-macosx_10_12_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

File details

Details for the file r4pm-0.5.5a1.tar.gz.

File metadata

  • Download URL: r4pm-0.5.5a1.tar.gz
  • Upload date:
  • Size: 79.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for r4pm-0.5.5a1.tar.gz
Algorithm Hash digest
SHA256 953d0bdcd49e127c36dba05f4144497f4c6775237f6d3240d37a31c9634b96fc
MD5 6e0d7ac0fccb6267bbb3d8497f170d6d
BLAKE2b-256 960c929a48e0357df46a4a729987e9fe09e173727e2eb805d2dee20ed32e7e66

See more details on using hashes here.

File details

Details for the file r4pm-0.5.5a1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: r4pm-0.5.5a1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 9.2 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for r4pm-0.5.5a1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c8bc6a4fcd86e51b31e195788b1094477ce987435a5ec38e34f6725313208c58
MD5 db438f54b4dce4345b1bfb659764ae7f
BLAKE2b-256 7cb6f679478d6945253402fa4a63e573b45d332b703066d416d358f63abd5f0f

See more details on using hashes here.

File details

Details for the file r4pm-0.5.5a1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for r4pm-0.5.5a1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 61f0081d7c300b7db7c1c2132e184d1ea86c86ad9f4ab51da78c2b8fa1c72b42
MD5 17e74e509e3928a343d29c71b3a84dab
BLAKE2b-256 7fd173bbb59e93815afb255cdc227a73479ee699995d87470cf4c0a379485ebb

See more details on using hashes here.

File details

Details for the file r4pm-0.5.5a1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for r4pm-0.5.5a1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f86307227d12d76d895bc90d377a5d9dd4dfb3d75ad0dbd38bbff5880b796291
MD5 1af97b1b7e4336bffe18813281948457
BLAKE2b-256 d4193bffdcbbfd237a4a66ed3ab1dc42d6b35b3c4433d1a36b25798f3a25225d

See more details on using hashes here.

File details

Details for the file r4pm-0.5.5a1-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for r4pm-0.5.5a1-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 16a4572eba4b787cdf52c40f77bdba1b968d43a53163cf04a94e65b1eb9fff9e
MD5 cf1fb5392ba7e10fb2709f66c9eac499
BLAKE2b-256 a71f18fd88e5d7bfb106267908f816582d6f79067cfbe14ab2c9deaf09c8e029

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page