Portable, human-readable bucketing rules for Python data workflows.
Project description
pickbuckets
Bucketing rules you can serialize, inspect, diff, and run anywhere.
pickbuckets turns raw numerical and categorical values into human-readable,
versioned bucketing rules. Fit a rule with the full stack (pandas, Polars,
scikit-learn), serialize it to JSON, and apply it in a plain-Python service with
no runtime dependencies. The same rule produces identical results in
training, batch scoring, online inference, and monitoring.
Portability in one example
Fit where the data lives; apply where the data doesn't.
# --- training environment (full stack available) ---
from pickbuckets import EqualFrequencyBucket
bucket = EqualFrequencyBucket(n_bins=4, duplicates="drop").fit(training_values)
payload = bucket.to_json() # store this string anywhere
# --- serving environment (standard library only) ---
from pickbuckets import Rule
from pickbuckets.runtime import apply_rule
rule = Rule.from_json(payload)
codes = apply_rule(rule, [0, 5, 10, None]) # no pandas / Polars / sklearn
apply_rule is pure Python (optionally NumPy) and is verified by a CI job with
pandas, Polars, and scikit-learn uninstalled.
Install
python -m pip install pickbuckets # dependency-free core
python -m pip install "pickbuckets[pandas]"
python -m pip install "pickbuckets[polars]" # Python 3.10+
python -m pip install "pickbuckets[sklearn]"
python -m pip install "pickbuckets[plot]"
python -m pip install "pickbuckets[all]"
python -m pip install -e ".[dev,all]" # development
Bucketers
Every bucketer fits to a single unified Rule and shares
the same fit / transform / summary / to_json shape. transform() uses
only the saved rule — never the training data.
| Bucketer | Kind | What it does | Needs |
|---|---|---|---|
EqualWidthBucket |
numeric | Equal-width bins from min/max | core |
EqualFrequencyBucket |
numeric | Quantile (equal-frequency) bins | core |
CustomBoundaryBucket |
numeric | Manual, validated edges (supports ±inf) |
core |
RareCategoryBucket |
categorical | Fold rare/unseen categories to a fallback | core |
AutoBucket |
mixed | One rule per column, dtype-driven dispatch | core |
WoEBucket |
supervised | WoE/IV with monotonic + min-bin-size constraints | core |
ChiMergeBucket |
supervised | Chi-square adjacent-bin merging | core |
DecisionTreeBucket |
supervised | Edges from a shallow decision tree | [sklearn] |
ExternalSplitBucket |
numeric | Import external splits (e.g. OptBinning) | core |
StreamingEqualFrequencyBucket |
numeric, experimental | Online/approximate quantile bins for out-of-core data | core |
Plotting helpers (pickbuckets.plotting, behind [plot]) return matplotlib
Axes for bucket counts, target rate, and WoE.
from pickbuckets import AutoBucket, EqualWidthBucket
frame = {"age": [18, 25, 34, 52, 70], "country": ["FR", "FR", "US", "DE", "DE"]}
auto = AutoBucket(
n_bins=3,
min_frequency=2,
overrides={"age": EqualWidthBucket(n_bins=3, labels="interval")},
).fit(frame)
print(auto.transform(frame))
Configurable, serializable policies cover missing values
(separate / most_frequent / propagate / error), numeric boundaries
(clip / underflow_overflow / error), and unknown categories
(other / missing / keep / error), each raising a clear typed exception.
Documentation
- Usage guide — worked examples for every bucketer and policy
- API reference — symbols, the
Rulemodel, runtime, exceptions - Integrations — pandas, Polars, and scikit-learn adapters
- Rule gallery — realistic portable JSON rules across ML use cases
- Benchmarks — reproducible speed and memory suite
- Changelog
When to use it
Use pickbuckets when ML buckets must be stable, reviewable, and identical
across training, batch scoring, online inference, and monitoring — tabular
preprocessing, feature-store transforms, score banding, drift slices, and
governed models such as credit scoring, fraud, churn, pricing, and insurance
risk. See the rule gallery for examples.
Development
ruff check .
mypy src/pickbuckets
pytest
python -m build
Contributions follow a few principles — keep the core import dependency-free, put integrations behind extras, fit once and transform from saved rules. See CONTRIBUTING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pickbuckets-0.5.0.tar.gz.
File metadata
- Download URL: pickbuckets-0.5.0.tar.gz
- Upload date:
- Size: 111.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0beb3b8d9ad7569ef9ca905d659c40f7caa49c41683eff0ed662a61b95f2fcd9
|
|
| MD5 |
d4e52475485a95676c6fa987526d1ccb
|
|
| BLAKE2b-256 |
234f5a3f50580e28fb5effd215d5577384799a4bbc61deef9e247e1722b503c4
|
File details
Details for the file pickbuckets-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pickbuckets-0.5.0-py3-none-any.whl
- Upload date:
- Size: 44.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc54e5ed97f46cf3938e0de3c9c9e0a1b5885b12703f95a783480f560dd1b049
|
|
| MD5 |
68f95fc32162ec497d242639e43e6c43
|
|
| BLAKE2b-256 |
fa70e1141a8616d2f37dca8ae98df15471aa3a4361948d19b8d3391db47a5e18
|