Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/get-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ npm install @datafog/wasm
Python](/guides/migrating-from-datafog-python).
</Warning>

## Upcoming DataFog Python bridge

The established `datafog` package is preparing an **unreleased 4.9 bridge**.
Its optional `datafog[rust]` extra will pin `datafog-core==0.3.1`, with Python
remaining the default backend. Explicit Rust detection will preserve legacy
result objects; `datafog.v5` will expose the native Core schema.

These bridge APIs are not available in `datafog` 4.8.1. Continue using the direct
`datafog-core` installation above for the examples on these pages. See
[Migrate from DataFog Python](/guides/migrating-from-datafog-python) for the
upcoming bridge, known coverage differences, and planned 5.0 removals.

## Runtime requirements

- Rust `1.88` or newer
Expand Down
114 changes: 110 additions & 4 deletions docs/guides/migrating-from-datafog-python.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: "Migrate from DataFog Python"
description: "Move from datafog 4.8.x to the canonical DataFog Core 0.3.x Python API."
description: "Migrate to DataFog Core directly or prepare for the unreleased Python 4.9 bridge."
icon: "arrow-right-arrow-left"
---

<Warning>
This guide covers migration of the synchronous text detection and
transformation API from `datafog` 4.8.x to `datafog-core` 0.2.x. DataFog
transformation API from `datafog` 4.8.x to `datafog-core` 0.3.x. DataFog
Core is a new canonical API, not a drop-in replacement for the established
DataFog Python package.
</Warning>
Expand All @@ -20,7 +20,113 @@ OCR, distributed-processing, CLI, or application-guardrail features. Keep the
established package for those workloads while adopting Core where its smaller,
cross-runtime contract fits.

## Change the package and import
## Upcoming Python 4.9 bridge (unreleased)

<Warning>
The following `datafog` APIs are planned for the unreleased 4.9 bridge in
[Python PR #178](https://github.com/DataFog/datafog-python/pull/178).
They are not available in the published 4.8.1 package. Installation commands
in this section apply once a package containing the bridge is released.
</Warning>

The bridge provides two separate adoption paths. Installing the optional extra
alone does not change existing detection behavior.

| Entry point | Detection | Result schema and transformation behavior |
| --- | --- | --- |
| `datafog.scan` / `datafog.redact` | Python by default; explicit `backend="rust"` uses Core | Existing `ScanResult` / `RedactResult`, numbered tokens and plaintext mappings |
| `datafog.compat.v4` | Same backend selection as the top-level facade | Same legacy classes, preserving their identity |
| `datafog.v5` | Core directly | Native `Finding` / `TransformResult` objects and Core strategies |

### Retain legacy results with Rust detection

```bash After the Python 4.9 bridge is released
python -m pip install "datafog[rust]"
```

The bridge's `rust` extra pins **`datafog-core==0.3.1`**. A base installation
requires no native module; `datafog[all]` retains its legacy dependencies, so
request `datafog[all,rust]` if both sets are needed.

```python Python 4.9 bridge (unreleased)
import datafog

result = datafog.scan("Contact alice@example.com", backend="rust")
assert result.entities[0].type == "EMAIL"

redacted = datafog.redact("Contact alice@example.com", backend="rust")
assert redacted.redacted_text == "Contact [EMAIL_1]"
assert redacted.mapping == {"[EMAIL_1]": "alice@example.com"}
```

`backend` is keyword-only and defaults to `"python"`. Rust supports only
`engine="regex"`. When calling `datafog.engine.scan` or `scan_and_redact`, pass
`engine="regex"` explicitly because those low-level functions default to
`"smart"`. Unsupported combinations and missing dependencies raise errors;
native failures propagate. There is **no silent fallback to Python**.

The adapter uses code-point offsets for Python indices, preserves Python
aliases and full-match allowlists, and keeps Python transformation behavior.
Its regex provenance and confidence `1.0` are compatibility values rather than
native probability estimates. Explicit-entity redaction performs no detection
and needs no native module.

`sanitize`, `scan_prompt`, and `filter_output` forward the backend keyword.
`TextService`, `DataFog`, CLI text commands, guardrail objects, application
adapters, and ML composition retain their existing detection paths in 4.9.

### Preview the native schema

```python Python 4.9 bridge (unreleased)
from datafog.v5 import Finding, scan, scan_and_transform

findings = scan("Contact alice@example.com")
assert isinstance(findings[0], Finding)
assert findings[0].entity_type == "EMAIL"

result = scan_and_transform(
"Contact alice@example.com",
{"transform": {"default": {"strategy": "redact"}}},
)
assert result.text == "Contact [EMAIL]"
```

The preview reexports the actual Core objects, including structured operations
and `PrivacyManager`; it does not translate legacy schemas or strategy names.
Importing `datafog` or the preview module alone does not load Core. Accessing
preview exports requires the native dependency. The direct Core guidance below
also applies to these native exports.

### Coverage limits and retirement schedule

Core **0.3.1** does not implement the seven German-specific detectors. The
legacy Rust adapter explicitly rejects German locales and `DE_*` selections;
use `backend="python"` for those workloads. Direct Core and `datafog.v5` retain
Core's own configuration semantics: accepting a locale does not establish
German detector coverage.

The bridge's finite 4.8.1 comparison corpus records two additional detector
differences: Core rejects the tested invalid-checksum credit-card value and the
SSN embedded in an alphanumeric token. This is an experimental alternative,
not a claim of universal parity. Review the
[Python migration evidence](https://github.com/DataFog/datafog-python/blob/6ebd4c86655e0561941475762a7d71e45204f60f/docs/migration-4.9.md)
before switching workloads.

| Surface | Planned 4.9 behavior | Planned 5.0 behavior |
| --- | --- | --- |
| `detect()` / `process()` | Remain available with revised deprecation warnings | Remove |
| OCR / Donut / Tesseract / image services | Remain available with use-time warnings | Remove APIs and extras |
| Spark / distributed processing | Remain available with use-time warnings | Remove APIs and extras |
| Legacy scan/redact facade | Top-level API and `compat.v4` remain available | Native schema becomes primary; compatibility lifetime set separately |
| spaCy / GLiNER | Unchanged | No removal decision in this increment |

The earlier commitment to retain `detect()` and `process()` through 5.x has
been revised: removal is planned for **5.0**. Neither shim is exposed through
`compat.v4` or `datafog.v5`. Replace them with explicit scan or transformation
calls, reviewing changed output semantics. Users needing OCR or Spark can stay
on the final 4.x release; no successor package is promised.

## Migrate directly: change the package and import

<CodeGroup>

Expand Down Expand Up @@ -190,7 +296,7 @@ Use canonical names such as `DATE` and `ZIP_CODE` rather than legacy aliases
such as `DOB` or `ZIP`. Entity selection belongs in the transformation config,
not the scan config.

## Migration checklist
## Direct Core migration checklist

- Replace the `datafog` distribution and `datafog.engine` imports.
- Consume the list returned by `scan` instead of `ScanResult.entities`.
Expand Down
18 changes: 18 additions & 0 deletions docs/reference/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ import datafog_core
calls.
</Note>

## Relationship to the upcoming Python 4.9 bridge

<Note>
The `datafog` 4.9 bridge is **unreleased**. The APIs below are available
directly from the published `datafog-core` package; the upcoming
`datafog.v5` namespace will reexport those same native objects.
</Note>

The bridge's optional `datafog[rust]` extra pins `datafog-core==0.3.1`.
`datafog.scan(..., backend="rust")` keeps legacy result objects and Python
redaction semantics. It is different from `datafog.v5.scan(...)`, which returns
native findings and uses the Core schema described on this page. Existing
`datafog` calls default to the Python backend even with the extra installed.

See the [bridge migration guide](/guides/migrating-from-datafog-python#upcoming-python-49-bridge-unreleased)
for installation timing, configuration limits, German detection gaps, and the
5.0 retirement schedule. Do not translate legacy strategy names mechanically.

## Type checking

Starting with 0.3.1, the wheel includes PEP 561 typing metadata and stubs for
Expand Down
Loading