Skip to main content

🔒 safesplit

PyPI Tests Python License: AGPL v3

Leakage-safe train/test splits — group-aware, time-aware, de-duplicated.

sklearn.train_test_split shuffles rows at random. For a lot of real data that quietly leaks: the same patient lands on both sides, a time series trains on its own future, or duplicate rows sit in train and test. Your score looks great and isn't real.

safesplit gives you one honest split:

pip install safesplit
from safesplit import safe_split

# a group is never on both sides
train, test = safe_split(df, group_col="patient_id")

# train on the past, test on the future
train, test = safe_split(df, time_col="date")

# keep near-homologous protein/DNA sequences together
train, test = safe_split(df, seq_col="sequence")

# plain random split, but exact duplicates are dropped first
train, test = safe_split(df, test_size=0.2)

What it does

You pass What you get
group_col every group (patient / user / device) stays entirely on one side
seq_col protein/DNA sequences that are similar stay on one side (homology-safe)
time_col a chronological split — train is the past, test is the future
dedupe=True (default) exact duplicate rows are removed before splitting
nothing extra a reproducible random split

The companion to LeakHound

safesplit prevents the leaks that LeakHound detects. Split with one, verify with the other:

from safesplit import safe_split
from leakhound import audit           # pip install leakhound-ml

train, test = safe_split(df, group_col="patient_id")
assert audit(train, test, group_col="patient_id").clean

License

GNU AGPL-3.0-or-later © 2026 Joel Gomes. A commercial license is available if the copyleft terms don't fit your use — open an issue.

Metadata

Release files for safesplit 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safesplit 0.3.0
File Size Uploaded
safesplit-0.3.0.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for safesplit 0.3.0
File Interpreter ABI Platform
safesplit-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.3 kB

Release files / safesplit-0.3.0.tar.gz

Download URL safesplit-0.3.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c21efc9ffd2cda425b34e69e2bc866e3cd3b7dbfb4502a02af0aef4590804367
BLAKE2b-256 checksum
How to use checksums
08f94c6a6ed3e7e53bb011fcde412170b0de89f67efbf94e27e7e0b86f2bbae1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / safesplit-0.3.0-py3-none-any.whl

Download URL safesplit-0.3.0-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbf8ca33a58bd48fb5542f2859aa41d6b5a83a2e19719a06063620007205c798
BLAKE2b-256 checksum
How to use checksums
ac88966e26d782bef0fee677711be49cec5180a33adf8dbb5ea741f72aa66e9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release 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