rfmkit
rfmkit scores customers by recency, frequency and monetary value and turns
those scores into segments, for marketing analysts and R learners who want the
same numbers as the R rfm package in pure
pandas and matplotlib (no compiled code, so it also runs in Pyodide).
Install
pip install rfmkit
Python 3.11+ with pandas 2.2+, numpy and matplotlib.
Example
import pandas as pd
from rfmkit import load_orders, rfm_table_order
orders = load_orders()
table = rfm_table_order(
orders,
customer_id="customer_id",
order_date="order_date",
revenue="revenue",
analysis_date=pd.Timestamp("2026-01-01"),
)
print(table.rfm.head(3).to_string(index=False))
customer_id recency_days transaction_count amount recency_score frequency_score monetary_score rfm_score
C0001 293.0 5 304.19 2 3 4 234
C0002 220.0 3 138.87 3 2 2 322
C0003 261.0 2 161.62 2 1 3 213
Segment the scored customers and summarise the result:
from rfmkit import rfm_segment, rfm_segment_summary
segments = rfm_segment(
table,
segment_names=["Champions"],
recency_lower=[5], recency_upper=[5],
frequency_lower=[5], frequency_upper=[5],
monetary_lower=[5], monetary_upper=[5],
)
print(rfm_segment_summary(segments))
rfmkit.datasets.load_orders() ships a synthetic two-year order history for
1,000 customers and 5,000 orders.
Differences from R
rfmkit reproduces the numbers of R rfm 0.5.1, including its tie handling and
binning quirks. These are the deliberate differences:
- Whole-number bin counts.
recency_bins=5.5raisesValueError; R accepts it and produces non-quintile cuts. - Date-time columns. A date-time
order_dateor recency column raisesTypeErrornaming the column; R silently computes a huge negative recency. - Constant extra columns with
NA. An extra order column is kept when its non-missing values are constant, even if one value isNA; R drops it. - Empty input. Returns a zero-row table; R fails inside
findInterval. - Fractional
n_transactions. Rejected up front withValueError; R fails at the very end. - Counts above
2**31 - 1. Kept as int64; R coerces values above the int32 range toNA. - One-item bin lists.
frequency_bins=[5]raisesValueError; it cannot clearly mean a bin count or a break point. rfm_segmentbound lengths. Every*_lower/*_upperargument must have the same length assegment_names; a mismatch raisesValueErrornaming the argument. R recycles length-1 bounds, so later rules can silently receiveNAand never match.
Documentation
https://rfmkit.rsquaredacademy.com
Licence
MIT.
Metadata
Release files for rfmkit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rfmkit-0.1.0.tar.gz | 1.8 MB | With provenance | Details for rfmkit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rfmkit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for rfmkit-0.1.0-py3-none-any.whl |
Total release size: 1.8 MB
Release files / rfmkit-0.1.0.tar.gz
| Download URL | rfmkit-0.1.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
556b61a9ccb62692c828008224e4a18537c2ae1f4295c55dec95a596350b9b8d
|
|
BLAKE2b-256 checksum How to use checksums |
0c87192838f4abb8ac438f5be20f90585ba0558022a0a3ed5a6c3910a193836a
|
| 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 28, 2026.
Transparency logRelease files / rfmkit-0.1.0-py3-none-any.whl
| Download URL | rfmkit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 49.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e6ff2c90e2965cf2cbc5a16e152bd4f39d0264176744e0a2a0e610a4580de07
|
|
BLAKE2b-256 checksum How to use checksums |
2801dec61f7d017a764df42730fa4a9926ea102e9d357929580d0b44def857ae
|
| 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 28, 2026.
Transparency logSecurity for rfmkit 0.1.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for rfmkit-0.1.0.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 28, 2026.
Transparency logA 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.