Redacting images by hand doesn't scale. If you're processing support attachments, bug reports, KYC documents or logs, you want personal data gone automatically. This tutorial shows how to detect and redact PII in images programmatically with the Privshot API, in a few lines of Python.

What you'll need

pip install requests

Redact an image and save the result

Send your image to POST /api/v1/redact with your key in the X-Api-Key header. Add ?format=binary to get the redacted image bytes straight back:

import requests

API_KEY = "ps_your_key_here"

with open("screenshot.png", "rb") as f:
    resp = requests.post(
        "https://privshot.com/api/v1/redact",
        headers={"X-Api-Key": API_KEY},
        files={"file": f},
        params={"format": "binary"},
    )

resp.raise_for_status()
with open("redacted.png", "wb") as out:
    out.write(resp.content)

print("Saved redacted.png")

That's the whole flow: image in, clean image out. Detection runs OCR plus pattern and NLP matching to find names, emails, phone numbers, cards, IBANs and 40+ national IDs.

Get the detections as JSON

Drop the format=binary parameter to get a JSON response instead. You receive the redacted image as base64 plus the list of entity types that were found. That's handy for logging or a review step:

import base64, requests

with open("screenshot.png", "rb") as f:
    resp = requests.post(
        "https://privshot.com/api/v1/redact",
        headers={"X-Api-Key": API_KEY},
        files={"file": f},
    )

data = resp.json()
print("Found:", data["entities_found"])       # e.g. ["EMAIL_ADDRESS", "PERSON"]

img = base64.b64decode(data["redacted"])
with open("redacted.png", "wb") as out:
    out.write(img)

Tune what gets redacted

A few request parameters let you control the result (see the full reference):

resp = requests.post(
    "https://privshot.com/api/v1/redact",
    headers={"X-Api-Key": API_KEY},
    files={"file": open("invoice.png", "rb")},
    data={"entities": "CREDIT_CARD,EMAIL_ADDRESS", "region": "eu"},
    params={"format": "binary"},
)

Use a solid box for sensitive data. blur and pixelate can sometimes be reversed. See why blurring is not safe redaction. The default box overwrites the pixels and is irreversible.

Make retries safe with an idempotency key

Networks fail. Send an Idempotency-Key header so a retried request never processes, or bills, the same image twice:

import uuid

resp = requests.post(
    "https://privshot.com/api/v1/redact",
    headers={"X-Api-Key": API_KEY, "Idempotency-Key": str(uuid.uuid4())},
    files={"file": open("screenshot.png", "rb")},
    params={"format": "binary"},
)

A note on detection quality

Automated detection is best-effort: it won't catch 100% of PII 100% of the time, and the API has no human-review step. For sensitive pipelines, use the JSON response to log what was found and add a verification step before trusting an output. A missed region is an un-redacted leak.

Next steps

That's everything you need to automate image redaction. The API docs cover every endpoint, parameter, entity type and rate limit. Prefer to redact a one-off by hand? Use the free web tool.