> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datafog.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Python functions, result objects, exceptions, and the asynchronous PrivacyManager.

```bash theme={null}
python -m pip install datafog-core
```

```python theme={null}
import datafog_core
```

<Note>
  Migrating from the established `datafog` package? Start with [Migrate from
  DataFog Python](/guides/migrating-from-datafog-python) before translating API
  calls.
</Note>

## Synchronous functions

```python theme={null}
scan(text: str, config: dict | None = None) -> list[Finding]
transform(text: str, findings: list[Finding], config: dict) -> TransformResult
scan_and_transform(text: str, config: dict) -> TransformResult
```

`transform` uses explicit findings. `scan_and_transform` accepts the divided
configuration envelope with `scan` and `transform` sections.

## Result objects

Python exposes immutable objects with snake\_case attributes:

* `TextRange(start, end)`
* `Finding`
* `Transformation`
* `TransformResult`
* `Restoration`
* `RestoreResult`

```python theme={null}
finding.entity_type
finding.matched_text
finding.byte_range.start
finding.codepoint_range.end

result.text
result.transformations
```

## Asynchronous manager

```python theme={null}
PrivacyManager(provider=None, token_provider=None)
```

The manager exposes awaitable methods:

```python theme={null}
await manager.transform(text, findings, config, context=None)
await manager.scan_and_transform(text, config, context=None)
await manager.restore(text, context)
```

The key provider must implement:

```python theme={null}
async def resolve_key(key_ref: str, key_version: str | None) -> dict:
    ...
```

The token provider must implement:

```python theme={null}
async def tokenize_batch(scope: str, items: list[dict]) -> list[dict]:
    ...

async def restore_batch(scope: str, items: list[dict]) -> list[dict]:
    ...
```

## Exceptions

* `DataFogConfigurationError`
* `DataFogFindingError`
* `DataFogKeyProviderError`
* `DataFogInternalError`

Exceptions expose stable `code`, optional `reason`, optional `path`, and
optional `finding_index` attributes. See [Errors](/reference/errors).

## Structured JSON and PERSON fields

Use `discover_fields(data, config=None)`, `scan_structured(data, config=None)`,
`transform_structured(data, findings, config)`, and
`scan_and_transform_structured(data, config)`. Results expose `.mappings` and
`.findings`, or `.data` and `.transformations`. `PrivacyManager` also exposes
`transform_structured`, `scan_and_transform_structured`, and `restore_structured`
for provider-backed work.

Paths are JSON Pointers. All ranges, including JavaScript UTF-16 ranges,
address the decoded string at that path. See [person-field discovery](/guides/person-discovery)
for aliases, policy configuration, input limits, and examples.
