Skip to main content

Lightweight decorator-based redaction for PII

Project description

📦 Piredactor

A lightweight, decorator-based Python package for redacting Personally Identifiable Information (PII) from function return values using a config-driven schema approach.


✅ Features

  • 🔐 Redact sensitive fields like email, password, tokens, phone numbers, credit card info, etc.
  • ⚙️ Configurable via JSON or YAML
  • 🎯 Supports nested structures, lists, and schema-based rules
  • 🧠 Supports exact, partial, and regex key matching
  • 🚀 Fast with internal caching (no re-parsing config per call)
  • 📌 Optional strict schema/data validation

📥 Installation

pip install piredactor  # after publishing

For development:

git clone <repo-url>
cd piredactor
pip install -e .

🚀 Usage

Step 1: Add Config File (JSON or YAML)

{
  "global": {
    "pii_keys": [
      "email", "phone", "mobile", "address", "name", "full_name", "dob",
      "birthdate", "ssn", "credit_card", "card_number", "cvv", "pan",
      "passport", "aadhaar", "zipcode", "zip", "pin", "ip", "location"
    ],
    "regex_keys": [
      "^.*token.*$", "^secret_.*$", "^auth_.*$", ".*_key$",
      "(?i)^.*credit.*card.*$", "(?i)^.*ssn.*$", "(?i)^.*dob.*$",
      "(?i)^.*ip(_address)?$", "(?i)^.*name.*$", "(?i)^.*phone.*$"
    ]
  },
  "user_data": {
    "schema": {
      "user": {
        "email": "pii",
        "password": { "pii": "HIDDEN" },
        "addresses": [
          {
            "zip": "pii",
            "city": "no_redact"
          }
        ]
      },
      "session": {
        "__regex_keys__": ["^auth_.*$"],
        "auth_token": "pii",
        "auth_key": "pii"
      }
    }
  }
}

Step 2: Decorate Your Function

from piredactor import redact_pii

@redact_pii(config_key="user_data", placeholder="REDACTED")
def get_user():
    return {
        "user": {
            "email": "test@example.com",
            "password": "mypassword",
            "addresses": [{"zip": "12345", "city": "Delhi"}]
        },
        "session": {
            "auth_token": "abcd1234",
            "auth_key": "mykey",
            "user_id": 42
        }
    }

⚙️ Options

Param Type Default Description
config_key str required Which schema to use from config
config_path str optional Custom config file path
placeholder str *** Value to replace PII fields
partial_match bool False Match fields partially
strict_validation bool False Raise if schema doesn't match payload

📜 License

MIT © 2025 Piyush Chauhan

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

piredactor-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

piredactor-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file piredactor-0.1.0.tar.gz.

File metadata

  • Download URL: piredactor-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for piredactor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80c5c7770d799c757c8b5fa07360a57dce29ef529f4cd4ae79c01f372e67ae8b
MD5 2f5b1efba6071312344c395f564483cd
BLAKE2b-256 28a1aba52e90c81e7f6582bf4399168ec7d1ff2acfd0aca994a3a78fa34f08ff

See more details on using hashes here.

File details

Details for the file piredactor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: piredactor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for piredactor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03be43d1ce978af80dc8deabededa05ec776c1ef601563d6e5e1d5194228e32f
MD5 32a8baa6ca2cee149604556a0ed58bc4
BLAKE2b-256 c2a3e039be92229259d55bd41830a4bad0701945e5047be107020eda7210b2ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page