stella-anonymize-core
Python bindings for the stella anonymization Rust core.
Install
Prebuilt wheels are published to PyPI (this activates with the next release). Wheels ship the bundled native pipeline packages, so no monorepo checkout is needed:
uv add stella-anonymize-core
# or: pip install stella-anonymize-core
Wheels target Python 3.11+ (abi3) on manylinux x64/aarch64, macOS x64/arm64,
and Windows x64. Only wheels are published; there is no source distribution.
The build.rs step needs the monorepo's generated .stlanonpkg native
pipeline packages, so a source build cannot be self-contained. To build from a
checkout instead, run bun run build first so those packages exist, then:
uv add ./crates/anonymize-py
Usage
Prepare or load the anonymizer once, then reuse it for documents.
import stella_anonymize as anonymize
languages = anonymize.available_default_native_pipeline_languages()
prepared = anonymize.preload_default_native_pipeline(
language="en" if "en" in languages else None
)
result = prepared.redact_text(text, redact_string="***")
print(result.redaction.redacted_text)
Reverse replacement placeholders with the returned redaction map (a mapping of
placeholder -> original, a sequence of RedactionEntry, or
(placeholder, original) pairs; entries apply in order):
restored = anonymize.deanonymise(
result.redaction.redacted_text,
result.redaction.redaction_map,
)
For related documents, create an explicit in-memory session from the prepared anonymizer. Repeated normalized entities reuse their placeholders within that session:
session = prepared.create_redaction_session("opaque_case_1")
first = session.redact_text(first_document)
second = session.redact_text(second_document)
restored_text = session.restore_text(first.redaction.redacted_text)
restore_text() restores complete known placeholders in one non-cascading
pass. Other session namespaces remain unchanged; unknown placeholders owned by
the session fail closed. Lifecycle sessions also require the caller-supplied
observed_at_epoch_seconds argument.
session.to_plaintext_json() supports deterministic in-memory transfer between
runtime instances. Its output contains original personal data in plaintext: do
not log it or persist it without an application-owned protection layer. Restore
validated transfer state with prepared.restore_redaction_session(json_state).
For persistence, use the authenticated binary archive API with a caller-owned 32-byte key. Restoring requires the expected session identity so an archive cannot be substituted across records:
archive = session.to_encrypted_archive(application_key)
restored = prepared.restore_encrypted_redaction_session(
archive,
application_key,
session.session_id(),
)
Generate, store, rotate, and authorize access to the key outside the SDK. The
archive contains personal data as ciphertext; do not log the archive or key.
Lifecycle sessions use to_encrypted_archive_at() and require
observed_at_epoch_seconds when restored.
Sessions can carry explicit lifecycle bounds. The engine never reads the system clock; supply the UTC epoch-second observation time for each lifecycle-aware operation:
session = prepared.create_redaction_session_with_lifecycle(
"opaque_case_2",
created_at_epoch_seconds=1_800_000_000,
expires_at_epoch_seconds=1_800_086_400,
)
result = session.redact_text_at(
document,
observed_at_epoch_seconds=1_800_000_100,
)
metadata = session.inspect(1_800_000_100) # contains no entity values
deletion = session.delete()
Expiry is fail-closed at its exact boundary. delete() performs logical
deletion: it clears the session mappings and prevents future use, but does not
revoke earlier exported copies or claim physical erasure of process memory.
Caller-produced detections use Python character indexes and enter the same resolution and redaction pipeline as built-in detections:
result = prepared.redact_text_with_caller_detections(
"😀Alice signed.",
[{"start": 1, "end": 6, "label": "person", "score": 0.95,
"provider_id": "example-ner", "detection_id": "person-1"}],
)
Pass {"organization": "keep"} as the operators argument to preserve
detected organizations while processing other labels normally. Kept entities
remain in the result and operator map, but create no reversible mapping entry.
Use a tagged mask configuration to replace a number of visible Unicode grapheme clusters from the start or end:
operators = {
"email address": {
"type": "mask",
"masking_character": "*",
"characters_to_mask": 6,
"direction": "start",
}
}
provider_id and detection_id are required 1–128 byte ASCII identifiers:
they start with an alphanumeric character and otherwise contain only
alphanumerics, ., _, :, or -. Do not encode personal data in them.
Retained entities preserve both IDs;
redact_text_with_caller_detections_diagnostics_json() reports audit-safe
external input and retained counts without matched text.
Regional codes use the exact package when present and otherwise fall back to
the base language package, so en-US can use the shipped en artifact.
For caller-owned configs, prepare package bytes before serving documents and load them at runtime:
import stella_anonymize as anonymize
package_bytes = anonymize.prepare_search_package(config_json)
prepared = anonymize.load_prepared_package(package_bytes)
prepared.warm_lazy_regex()
result = prepared.redact_text(text, redact_string="***")
get_default_native_pipeline() defers lazy regex warmup by default so the first
call only pays for regexes the document actually touches. Use
preload_default_native_pipeline() or pass warmup="lazy-regex" when startup can
absorb that cost before serving documents. Top-level redact_text() and
redact_text_json() are available for one-off calls, but they prepare from config
on each invocation. Use load_prepared_package() or load_prepared_package_file()
for repeated document processing.
API
prepare_search_package(config_json | config_bytes | config_mapping, compressed=True) -> bytesload_prepared_package(package_bytes) -> PreparedAnonymizerload_prepared_package_file(package_path) -> PreparedAnonymizeravailable_default_native_pipeline_languages() -> tuple[str, ...]read_default_native_pipeline_package_file(language=None) -> bytesget_default_native_pipeline(language=None, package_path=None, warmup="none") -> PreparedAnonymizerpreload_default_native_pipeline(language=None, package_path=None) -> PreparedAnonymizerPreparedAnonymizer.warm_lazy_regex()PreparedAnonymizer.warm_lazy_regex_diagnostics_json()PreparedAnonymizer.create_redaction_session(session_id) -> PreparedRedactionSessionPreparedAnonymizer.create_redaction_session_with_lifecycle(...) -> PreparedRedactionSessionPreparedAnonymizer.restore_redaction_session(plaintext_json) -> PreparedRedactionSessionPreparedRedactionSession.restore_text(full_text, observed_at_epoch_seconds=None) -> strdeanonymise(redacted_text, redaction_map) -> strPreparedAnonymizer.redact_text(text, operators=None, redact_string=None)PreparedAnonymizer.redact_text_json(text, operators=None, redact_string=None)PreparedAnonymizer.diagnostics_json(text, operators=None, redact_string=None)
PreparedSearch is an alias for PreparedAnonymizer.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 stella_anonymize_core-2.2.0-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: stella_anonymize_core-2.2.0-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 26.3 MB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
700b6fe9fe93dced1be2008496ecb38a2fee232f0b5ecc1157fce14b4773393d
|
|
| MD5 |
8740c340b852c26e0ba131d047ad9ad4
|
|
| BLAKE2b-256 |
fab39ddf70612891f2d1f460f791f52595fd6035142fd7088f28579dce9b9253
|
Provenance
The following attestation bundles were made for stella_anonymize_core-2.2.0-cp311-abi3-win_amd64.whl:
Publisher:
release.yml on stella/anonymize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stella_anonymize_core-2.2.0-cp311-abi3-win_amd64.whl -
Subject digest:
700b6fe9fe93dced1be2008496ecb38a2fee232f0b5ecc1157fce14b4773393d - Sigstore transparency entry: 2200595252
- Sigstore integration time:
-
Permalink:
stella/anonymize@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 26.4 MB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69fa350c462674782adf479eb5827d1697827a6e0d4f9c67b4677bf2d02b42bf
|
|
| MD5 |
eea11ce87e73a45aabc9f4086c5a9b29
|
|
| BLAKE2b-256 |
e9ee1cc99a81a92857546139e8d3f71cab3610f59b2e874355485e92e62006dd
|
Provenance
The following attestation bundles were made for stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on stella/anonymize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
69fa350c462674782adf479eb5827d1697827a6e0d4f9c67b4677bf2d02b42bf - Sigstore transparency entry: 2200595339
- Sigstore integration time:
-
Permalink:
stella/anonymize@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 26.2 MB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9cb08b860335fb56f2ba809be7f7880d9b50ed671f1c2ca4ab10ae2658cd32c
|
|
| MD5 |
fe835d6eb9a70a0b4c6725b868783de1
|
|
| BLAKE2b-256 |
eb340a75f5e7dd7e308b2b44ab3b4f9e6e17d1487da0e340d81779a8af3b9f5d
|
Provenance
The following attestation bundles were made for stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on stella/anonymize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stella_anonymize_core-2.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
b9cb08b860335fb56f2ba809be7f7880d9b50ed671f1c2ca4ab10ae2658cd32c - Sigstore transparency entry: 2200595316
- Sigstore integration time:
-
Permalink:
stella/anonymize@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file stella_anonymize_core-2.2.0-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: stella_anonymize_core-2.2.0-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 26.0 MB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9a6aa94c86c1b89b8e71ab65ba13c190b81af93c719c155f0f4827271a09f2e
|
|
| MD5 |
9aaa3d7a33006719cdcb4b81d886c239
|
|
| BLAKE2b-256 |
2692d7980493ef13a6c3a7fb9714f31d301ba9689544a403bb5537f78c4f0133
|
Provenance
The following attestation bundles were made for stella_anonymize_core-2.2.0-cp311-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on stella/anonymize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stella_anonymize_core-2.2.0-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
a9a6aa94c86c1b89b8e71ab65ba13c190b81af93c719c155f0f4827271a09f2e - Sigstore transparency entry: 2200595285
- Sigstore integration time:
-
Permalink:
stella/anonymize@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file stella_anonymize_core-2.2.0-cp311-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: stella_anonymize_core-2.2.0-cp311-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 26.2 MB
- Tags: CPython 3.11+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
021c5b935273b31a0d842498b40d3a4d0c4fa8a3fa738972a63e27256248bf95
|
|
| MD5 |
94fb7d80223fc178875cf64c3b9ad6ee
|
|
| BLAKE2b-256 |
071dd65c17b254f62835b6c80779a673b3d460e9e7717ea30b366ecb5321dd5f
|
Provenance
The following attestation bundles were made for stella_anonymize_core-2.2.0-cp311-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on stella/anonymize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stella_anonymize_core-2.2.0-cp311-abi3-macosx_10_12_x86_64.whl -
Subject digest:
021c5b935273b31a0d842498b40d3a4d0c4fa8a3fa738972a63e27256248bf95 - Sigstore transparency entry: 2200595329
- Sigstore integration time:
-
Permalink:
stella/anonymize@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stella
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@34b37b15f6f536fdda6d5e2583b0a70018af44bc -
Trigger Event:
push
-
Statement type: