Skip to main content

Lightweight, customizable PII masking for emails and phone numbers.

Project description

mask-pii (Python)

Version: 0.2.0

A lightweight, customizable Python library for masking Personally Identifiable Information (PII) such as email addresses and phone numbers.

It is designed to be safe, fast, and easy to integrate into logging or data processing pipelines.

Official website: https://finitefield.org/en/oss/mask-pii Developed by: Finite Field, K.K.

Features

  • Email Masking: Masks the local part while preserving the domain (e.g., a****@example.com).
  • Global Phone Masking: Detects international phone formats and masks all digits except the last 4.
  • Customizable: Change the masking character (default is *).
  • Zero Unnecessary Dependencies: Pure Python implementation.

Installation

From PyPI:

pip install mask-pii

From a local checkout:

pip install -e ./python

Usage

from mask_pii import Masker

masker = (
    Masker()
    .mask_emails()
    .mask_phones()
    .with_mask_char("#")
)

input_text = "Contact: alice@example.com or 090-1234-5678."
output = masker.process(input_text)

print(output)
# => "Contact: a####@example.com or ###-####-5678."

Configuration

The Masker class uses a builder-style API. By default, Masker() performs no masking (pass-through).

Builder Methods

Method Description Default
mask_emails() Enables detection and masking of email addresses. Disabled
mask_phones() Enables detection and masking of global phone numbers. Disabled
with_mask_char(char) Sets the character used for masking (e.g., "*", "#", "x"). "*"

Masking Logic Details

Emails

  • Pattern: Detects standard email formats.
  • Behavior: Keeps the first character of the local part and the domain. Masks the rest of the local part.
  • Example: alice@example.com -> a****@example.com
  • Short Emails: If the local part is 1 character, it is fully masked (e.g., a@b.com -> *@b.com).

Phones (Global Support)

  • Pattern: Detects sequences of digits that look like phone numbers (supports international +81..., US (555)..., and hyphenated 090-...).
  • Behavior: Preserves formatting (hyphens, spaces, parentheses) and the last 4 digits. All other digits are replaced.
  • Examples:
    • 090-1234-5678 -> ***-****-5678
    • +1 (800) 123-4567 -> +* (***) ***-4567
    • 12345 -> *2345

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

mask_pii-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

mask_pii-0.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file mask_pii-0.2.0.tar.gz.

File metadata

  • Download URL: mask_pii-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mask_pii-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a154e54fc4796c7429776e3759650f27f2c90779acb2d221085d8de8a269e12d
MD5 2fb932cd4a97e5b03a2c22871d5662ee
BLAKE2b-256 c22c83b14bd47050ac734d5831de71925c935a08a0d0e26d9d9130c3df5cd95d

See more details on using hashes here.

File details

Details for the file mask_pii-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mask_pii-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mask_pii-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 157b6f665c736430e477ccb8569b2e42c083f0bef52c6d51aace60313fd18721
MD5 b7364131669fc7b5835bfdf3ce4e06c6
BLAKE2b-256 121cc5514c42a9dab822cc42e6c48f6f173a6b3c702967fdd5f267a38a818410

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