Skip to main content

Enterprise PII Masking, Tokenization & Encryption Module

Project description

PII Engine

A stateless, high-performance, and standalone PII (Personally Identifiable Information) processing module designed for SQLAlchemy models.

Features

  • Transparent PII: Access PII fields on your models as if they were plain text. The engine handles unmasking on-the-fly.
  • Stateless Architecture: No database dependencies. All encryption and pseudonymization are performed in-memory.
  • Model-Level Integration: Easy-to-use mixins and descriptors for SQLAlchemy.
  • Centralized Configuration: Configure the engine once at application startup.
  • Auto-Presigned URLs: Automatically generates S3 presigned URLs for PII fields containing S3 paths.

1. Quick Setup

Configure the engine in your main application entry point (e.g., main.py).

import pii_engine

pii_engine.configure(
    pii_enc_key="your-encryption-key",
    aws_s3_bucket="your-bucket-name",
    aws_region="us-east-1"
)

2. Model Integration

Use PIIBase mixin and PIIProperty/PIIUrlProperty descriptors to make your models "Transparent".

Define your Model

from sqlalchemy import Column, String, Text
from pii_engine import PIIBase, PIIProperty, PIIUrlProperty
from your_app.database import Base

class Employer(Base, PIIBase):
    __tablename__ = "employers"
    
    # Internal columns (prefixed with _)
    _first_name = Column("first_name", String(100))
    _resume_url = Column("resume_url", String(255))
    
    # This stores the encryption tokens for the row
    TOKEN_SET = Column(Text) 

    # Transparent PII Properties
    first_name = PIIProperty("employers", "first_name")
    resume_url = PIIUrlProperty("employers", "resume_url")

3. Usage

Saving Data (Masking)

The update_pii method handles masking and token generation automatically. It merges new tokens with existing ones to prevent data loss.

employer = Employer()
data = {"first_name": "John Doe", "resume_url": "s3://bucket/resumes/john.pdf"}

# This masks data and sets TOKEN_SET
employer.update_pii(data) 
db.add(employer)
db.commit()

Retrieving Data (Unmasking)

Just access the attributes directly.

# Returns "John Doe" (unmasked)
print(employer.first_name) 

# Returns a signed S3 URL
print(employer.resume_url) 

4. Configuration Options

The configure() method accepts the following parameters:

Parameter Default Description
pii_enc_key env:PII_ENC_KEY Key used for Fernet encryption.
aws_s3_bucket env:AWS_S3_BUCKET S3 bucket for URL signing.
aws_region us-east-1 AWS region for S3 client.

Architecture Note

This engine is designed to be Stateless. Unlike older versions, it does not require a pii_vault database table. All reversal information is stored within the model's own TOKEN_SET column using reversible encryption.

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

tns_pii_engine-1.0.2.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

tns_pii_engine-1.0.2-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file tns_pii_engine-1.0.2.tar.gz.

File metadata

  • Download URL: tns_pii_engine-1.0.2.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for tns_pii_engine-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6bac26802f01f42a738f1ce7417f65237d9ac9b7608061d070a376433b2e2fa8
MD5 e8c4d5e741315048844c3b51fab3a29c
BLAKE2b-256 62441f8e13e7f96dbb2408d09cd7cf6e33fc36847a8b4caa44ff2e05dc1db916

See more details on using hashes here.

File details

Details for the file tns_pii_engine-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: tns_pii_engine-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for tns_pii_engine-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c562bf30809f2d28c150a17266c7f0fe5ccf9bee367cf566f023230a9125b145
MD5 12f9bcc9dd0adb34e2137eec90cf943b
BLAKE2b-256 19dc3823af39c82c231048fd6331d11b4ce98fef75cd3dcad6047c563a028735

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