FastPII Docs
Integrations

FastAPI

Expose FastPII detection and validation through a FastAPI application with built-in API endpoints.

FastAPI integration

FastPII includes a FastAPI integration that creates an application with detection, validation, detector listing, and health endpoints.

Installation

pip install fastpii[fastapi]

Setup

Import and create the app:

from fastpii.integrations.fastapi import create_app

app = create_app()

You can also run the bundled app directly:

uvicorn fastpii.integrations.fastapi:app

Usage examples

Detect PII

curl -X POST http://127.0.0.1:8000/detect \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Jan Novak, rodne cislo 8001011234",
    "regions": ["cz"],
    "detector_names": null
  }'

Validate an identifier

curl -X POST http://127.0.0.1:8000/validate \
  -H "Content-Type: application/json" \
  -d '{
    "value": "8001011234",
    "detector_name": "rodne_cislo",
    "regions": ["cz"]
  }'

List detectors

curl "http://127.0.0.1:8000/detectors?regions=cz"

Health check

curl http://127.0.0.1:8000/health

API reference

POST /detect

Request body:

{
  "text": "string",
  "regions": ["cz"],
  "detector_names": ["string"]
}
  • text: text to analyze
  • regions: list of region codes, defaults to ["cz"]
  • detector_names: optional list of detector names

Response model:

{
  "text": "string",
  "findings": [
    {
      "type": "string",
      "value": "string",
      "start": 0,
      "end": 0,
      "confidence": 0.0,
      "region": "string",
      "metadata": {}
    }
  ],
  "detector_names": ["string"],
  "processing_time_ms": 0
}

Each item in findings matches FindingResponse:

  • type
  • value
  • start
  • end
  • confidence
  • region
  • metadata

POST /validate

Request body:

{
  "value": "string",
  "detector_name": "string",
  "regions": ["cz"]
}

Response model:

{
  "detector": "string",
  "value": "string",
  "is_valid": true,
  "metadata": {}
}

If the detector is not found, the endpoint raises an HTTP 404 error.

GET /detectors

Query parameters:

  • regions: optional repeated query parameter for region codes

Response model:

[
  {
    "name": "string",
    "region": "string",
    "description": "string"
  }
]

GET /health

Response:

{
  "status": "healthy"
}

On this page