FastPII Docs
Reference

API Reference

Complete reference for PrivacyGuard and the exported FastPII data models.

Imports

from fastpii import PrivacyGuard, Finding, DetectionResult, ValidationResult

PrivacyGuard

Constructor

PrivacyGuard(regions: list[str] | None = None)
ParameterTypeDescription
regions`list[str]None`

Methods

detect

detect(text: str, detector_names: list[str] | None = None) -> DetectionResult
ParameterTypeDescription
textstrInput text to scan
detector_names`list[str]None`
ReturnsTypeDescription
return valueDetectionResultDetection output with findings and timing

validate

validate(value: str, detector_name: str) -> ValidationResult
ParameterTypeDescription
valuestrValue to validate
detector_namestrDetector that should validate the value
ReturnsTypeDescription
return valueValidationResultValidation outcome and detector metadata

anonymize

anonymize(text: str, replacement: str = "[REDACTED]") -> str
ParameterTypeDescription
textstrInput text containing PII
replacementstrPlaceholder used for every detected span

redact

redact(text: str) -> str

Returns text where each finding is replaced with a label such as [EMAIL] or [RODNE_CISLO].

mask

mask(text: str) -> str

Returns text where each finding is replaced by * characters matching the original value length.

remove

remove(text: str) -> str

Returns text with detected PII removed entirely.

register_detector

register_detector(detector) -> None

Registers a custom detector instance.

get_detector

get_detector(name: str)

Returns the detector registered under name.

list_detectors

list_detectors() -> list

Returns all registered detector instances.

Exported data models

Finding

FieldTypeDescription
typestrDetector type, such as email or ico
valuestrMatched value
startintStart index in the original text
endintEnd index in the original text
confidencefloatConfidence score for the match
regionstrRegion code such as cz
metadatadict[str, Any]Optional detector-specific metadata

DetectionResult

FieldTypeDescription
textstrOriginal text passed to detect()
findingslist[Finding]Deduplicated findings
detector_nameslist[str]Types of findings that survived overlap resolution
processing_time_msintDetection time in milliseconds

ValidationResult

FieldTypeDescription
detectorstrDetector name used for validation
valuestrValue passed to validate()
is_validboolWhether validation succeeded
metadatadict[str, Any]Optional detector-specific metadata

Example

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])

result = guard.detect("Jan Novák, email: jan.novak@email.cz, RČ: 8001011238")
validation = guard.validate("25596641", "ico")

On this page