Skip to main content
This guide covers migration of the synchronous text detection and transformation API from datafog 4.8.x to datafog-core 0.2.x. DataFog Core is a new canonical API, not a drop-in replacement for the established DataFog Python package.
DataFog Core makes detection results, text ranges, transformation policy, and provider-backed operations consistent across Rust, Python, Node.js, and browser/WASM. That consistency requires a few deliberate API changes in Python. DataFog Core 0.3 does not replace the legacy package’s optional spaCy, GLiNER, 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

The distribution name uses a hyphen (datafog-core), while the Python import uses an underscore (datafog_core). The two distributions can be installed at the same time while an application is migrated incrementally.

Update scan results

DataFog Python returns a ScanResult wrapper. DataFog Core returns a list of Finding objects directly.
Use codepoint_range when slicing a Python string. Use byte_range when addressing the UTF-8 encoded input. Both ranges are zero-based and end-exclusive. Rule-based Core findings can have confidence=None. Do not assume every finding has a numeric confidence score.

Replace scan-and-redact calls

DataFog Core separates detection configuration from transformation policy. transform requires explicit findings; scan_and_transform is the convenience operation that performs both steps.
Transformation records describe what was applied, including source and output ranges, but intentionally omit the original matched PII.

Choose the intended transformation

Do not migrate strategy names mechanically. In particular, legacy token and Core tokenize have different security and reversibility semantics. Core also adds remove, which deletes only the exact finding span.
For a strictly non-reversible first pass, choose redact, mask, or remove. Core pseudonymize is keyed and one-way but intentionally linkable; Core tokenize is reversible through the configured token provider.
See Privacy transformations for the full behavior and threat-model distinctions.

Remove legacy engine selection

Do not translate engine="regex", "smart", "spacy", or "gliner" into Core configuration. DataFog Core 0.3 owns detector composition and exposes locale as its scan setting. Detector provenance appears on each finding. Entity names are exact and case-sensitive. The built-in Core entities are: EMAIL, PHONE, SSN, CREDIT_CARD, IP_ADDRESS, DATE, and ZIP_CODE. 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

  • Replace the datafog distribution and datafog.engine imports.
  • Consume the list returned by scan instead of ScanResult.entities.
  • Rename entity fields and select codepoint_range or byte_range explicitly.
  • Replace scan_and_redact with scan_and_transform and a transformation envelope.
  • Remove legacy engine selectors and normalize entity names.
  • Select a Core strategy by behavior, especially for token and pseudonymize.
  • Stop depending on plaintext mappings or original PII in transformation records.
  • Update error handling for the DataFog Core exceptions.
Continue with the Python reference, then review findings and ranges and configuration.