rehuman (Python)
Unicode-safe text cleaning & normalization for Python, backed by the native
Rust rehuman core (PyO3 + maturin). Strip invisible characters, normalize
typography, and enforce ASCII/keyboard-safe output for text sourced from web
scraping, user input, or LLMs.
Install
The package is published on PyPI as rehuman:
pip install rehuman
- Requires Python 3.9+ (abi3 wheels: one wheel per platform covers every supported CPython).
- Prebuilt wheels: Linux (x86_64, aarch64), macOS (arm64), Windows (x86_64).
- Other platforms install from the sdist, which compiles the native module and needs a Rust toolchain. Wheel coverage details live in Release Automation.
- Published wheels are built with the default Rust features:
rehuman.HAS_STATSisTrueandrehuman.HAS_SECURITYisFalse.
Quickstart
clean() and humanize() both return str but target different outputs:
clean produces ASCII/keyboard-safe text, humanize keeps Unicode and tidies
typography and whitespace (exact policy differences).
import rehuman
text = "A B 👍 Café"
cleaned = rehuman.clean(text) # "A B Cafe"
humanized = rehuman.humanize(text) # "A B 👍 Café"
assert cleaned == "A B Cafe"
assert humanized == "A B 👍 Café"
# Use Cleaner for change counts and stats
cleaner = rehuman.Cleaner()
result = cleaner.clean("Hi\u200bthere \U0001f44d")
print(result.text) # "Hithere"
print(result.changes_made) # e.g. 3
print(result.stats) # dict with per-operation counters
Option-level control (non_ascii_policy, presets, line endings, ...) goes
through Options and Cleaner.
Advanced usage: cleaning a text corpus
A concrete case study: normalizing model-generated text in a training corpus (SFT conversations, synthetic data, scraped documents). Such text tends to carry invisible codepoints (zero-width spaces, soft hyphens), typographic quotes/dashes/ellipses, and exotic whitespace. Normalizing it removes stylistic tells and collapses spurious token variants without touching content.
Two decisions matter up front:
- Do not use default
clean()on corpora you care about. It targets ASCII/keyboard-safe output and deletes what it cannot transliterate, so non-Latin scripts vanish ("日本語テキスト hello"becomes"hello"). - Derive from the
code_safepreset instead. It keeps every script, emoji, and diagram glyph, strips hidden/control characters, and normalizes typographic quotes and dashes. Usereplaceto adjust it:
import rehuman
OPTIONS = rehuman.Options.code_safe_preset().replace(
normalize_other=True, # also fold ellipsis -> "..." etc.
unicode_normalization="nfc", # canonical form, no visual change
)
def clean_batch(batch):
cleaner = rehuman.Cleaner(OPTIONS) # construction is ~1 microsecond
results = [cleaner.clean(t) for t in batch["text"]]
return {
"text": [r.text for r in results],
"rehuman_changes": [r.changes_made for r in results],
}
This shape drops straight into map-style pipelines, for example Hugging Face
datasets: ds.map(clean_batch, batched=True, num_proc=8). Options and
Cleaner pickle, so worker processes and cache fingerprinting work; clean
releases the GIL, so thread pools scale too. Throughput is roughly a
thousand few-KB documents per second per core, linear in processes.
Keeping changes_made as a column is deliberate: sort by it descending and
eyeball the most-rewritten samples before training on the output.
One caveat: transforms apply to the whole string with no markdown or code
awareness. A fenced code block whose literals contain typographic characters
gets rewritten like any other text (text.replace("“", '"') breaks). If your
corpus is code-heavy, split out fenced blocks and clean only the prose.
Documentation
- Python API Reference: functions, classes, presets, constants, and errors.
- Rust core semantics: what each option and preset actually does; the bindings map onto these one-to-one.
- Release Automation: wheel/sdist build and PyPI publish flows.
Development
Build the extension into a local venv and run the test suite:
cd python
python -m venv .venv
source .venv/bin/activate
pip install -U pip maturin pytest
maturin develop
pytest -q
Metadata
Release files for rehuman 0.2.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 |
|---|---|---|---|---|
| rehuman-0.2.0.tar.gz | 72.6 kB | With provenance | Details for rehuman-0.2.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| rehuman-0.2.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for rehuman-0.2.0-cp39-abi3-win_amd64.whl |
| rehuman-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for rehuman-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| rehuman-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details for rehuman-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| rehuman-0.2.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details for rehuman-0.2.0-cp39-abi3-macosx_11_0_arm64.whl |
Total release size: 2.1 MB
Release files / rehuman-0.2.0.tar.gz
| Download URL | rehuman-0.2.0.tar.gz |
|---|---|
| Size | 72.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb27688fe97b819675461562dd64a6b54712e1d6520d925f53f2de64c1fbfada
|
|
BLAKE2b-256 checksum How to use checksums |
9524105ab060b37f6e78d88af417d27a5aad3b9a9301aeb1069f3774c1b9e0cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jul 16, 2026.
Transparency logRelease files / rehuman-0.2.0-cp39-abi3-win_amd64.whl
| Download URL | rehuman-0.2.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 448.9 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1f69385108d8d252c2b44383dc7376b3be88367ff723d8e6b256bbf2a3a447fe
|
|
BLAKE2b-256 checksum How to use checksums |
223c8f03ab9f88101ed1eeca0c60c00a03591d13ee334da01ecee0572436737a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jul 16, 2026.
Transparency logRelease files / rehuman-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | rehuman-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 541.6 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ab5e00a321b8749daead0f05aa10f81c15ada9a3affe2c37a99670236df45721
|
|
BLAKE2b-256 checksum How to use checksums |
11292072422f7e8295492a33fa79d43f349153d2b31d7cf4caf53cb8cd7dd63f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jul 16, 2026.
Transparency logRelease files / rehuman-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | rehuman-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 535.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4c92a47d1f516d9339a61e98a45cd77b629d1de300fa6465097e3a4236e0f78a
|
|
BLAKE2b-256 checksum How to use checksums |
dacae8cbdaba1a748ee6e785381580635ae755cbcc9c0bbf6b8f0ffc631f54b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jul 16, 2026.
Transparency logRelease files / rehuman-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | rehuman-0.2.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 520.2 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
cc07c5a9929ea35c2f8796dd46a100f37d32e3064a7378cd1a6e68f922c380f3
|
|
BLAKE2b-256 checksum How to use checksums |
0ccefd0de6212aaf96ca62a4e8612bc287905b1523d95c857f0ad84b5f02601e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jul 16, 2026.
Transparency logSecurity for rehuman 0.2.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
All 5 files in this release have been uploaded with provenance metadata.
Attestation for rehuman-0.2.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 Jul 16, 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.