FastPII Docs
Integrations

FastAPI

Drop-in REST API for PII detection and validation.

FastAPI

FastPII provides a FastAPI integration with built-in endpoints for detection, validation, and listing detectors.

Installation

pip install fastpii[fastapi]

Quick start

from fastpii import FastPII, DEFAULT_PRIORITY, DEFAULT_CONFIDENCE_SCORES, DEFAULT_CONTEXT_BOOST
from fastpii.core.confidence import ConfidenceScorer
from fastpii.integrations.fastapi import create_app
from fastpii.countries.cz import CzechPack

scorer = ConfidenceScorer(
    base_scores=DEFAULT_CONFIDENCE_SCORES,
    context_boost=DEFAULT_CONTEXT_BOOST,
)
engine = FastPII(priority=DEFAULT_PRIORITY, confidence_scorer=scorer)
engine.register(CzechPack())

app = create_app(engine)

Per-request regions

If you do not pass an engine, the API creates one per request from the regions field:

from fastpii.integrations.fastapi import create_app

app = create_app()

Endpoints

POST /detect

{
    "text": "Email: jan.novak@example.cz, RČ: 8001011238",
    "regions": ["cz"],
    "detector_names": null
}

Response:

{
    "text": "Email: jan.novak@example.cz, RČ: 8001011238",
    "findings": [
        {
            "type": "email",
            "value": "jan.novak@example.cz",
            "start": 7,
            "end": 27,
            "confidence": 0.95,
            "region": "cz",
            "metadata": {}
        },
        {
            "type": "rodne_cislo",
            "value": "8001011238",
            "start": 33,
            "end": 43,
            "confidence": 1.0,
            "region": "cz",
            "metadata": {
                "checksum_valid": true,
                "birth_date": "1980-01-01",
                "gender": "male",
                "article_9": true
            }
        }
    ],
    "detector_names": ["email", "rodne_cislo"],
    "processing_time_ms": 2
}

POST /validate

{
    "value": "8001011238",
    "detector_name": "rodne_cislo",
    "regions": ["cz"]
}

Response:

{
    "detector": "rodne_cislo",
    "value": "8001011238",
    "is_valid": true,
    "metadata": {
        "checksum_valid": true,
        "birth_date": "1980-01-01",
        "gender": "male"
    }
}

GET /detectors

GET /detectors?regions=cz

Response:

[
    {"name": "rodne_cislo", "region": "cz", "description": "Czech birth number"},
    {"name": "ico", "region": "cz", "description": "Czech company ID"},
    ...
]

GET /health

{"status": "healthy"}

Running the server

uvicorn fastpii.integrations.fastapi:app --host 0.0.0.0 --port 8000

Or with your own engine:

import uvicorn
from fastpii.integrations.fastapi import create_app

app = create_app(engine)
uvicorn.run(app, host="0.0.0.0", port=8000)

Production APIs

The FastAPI integration above provides a simple local server for SDK-level detection and validation. For production use, FastPII offers dedicated hosted APIs:

Detection API

The Detection API provides hosted PII detection and validation at https://api.fastpii.com/api/v1/. It uses API key authentication and includes Intelligence Engine auto-detection, batch support, and privacy presets.

Protection API

The Protection API provides hosted PII protection at https://api.fastpii.com/api/v1/. It supports five protection modes: replace, mask, hash, tokenize, and policy.

AI Gateway

The AI Gateway at https://gateway.fastpii.com provides real-time PII protection for LLM traffic with policy-based enforcement, audit logging, and multi-provider support.

FastPII Connect

For a typed Python client that calls these production APIs, see FastPII Connect. It provides FastPIIClient with session management, automatic retries, and CLI access.

Authentication comparison

APIAuthenticationBase URL
SDK FastAPI integrationNone (local)Local server
Detection APIAPI Key (Bearer fpk_...)https://api.fastpii.com
Protection APIAPI Key (Bearer fpk_...)https://api.fastpii.com
AI GatewayService Token (X-Service-Token)https://gateway.fastpii.com

On this page