Skip to main content

Maskify - Sensitive Data Masking Library for Python

Maskify is a lightweight, flexible library for Python, inspired by the Maskify.Core library for .NET. It helps developers securely mask sensitive data, such as Brazilian documents (CPF, CNPJ), emails, credit cards, and phone numbers. This library provides built-in masking for common data types, along with customizable masking options to ensure compliance with data protection regulations.

Features

  • Mask CPF and CNPJ: Easily mask Brazilian CPF and CNPJ numbers.
  • Email Masking: Partially mask email addresses.
  • Credit Card Masking: Mask credit card numbers while preserving the last few digits.
  • Phone Number Masking: Support for mobile and residential phone numbers.
  • Custom Masking: Mask any string by specifying a start position, length, and masking character.

Installation

To install Maskify, run:

pip install maskify-py

Usage

Below are examples of using Maskify for different types of sensitive data.

1. Masking CPF

The CPF format consists of 11 digits. Maskify will retain the last two digits and mask the middle portion:

from maskify.masker import Masker

cpf = "123.456.789-01"
masked_cpf = Masker.mask_cpf(cpf, "*")
print("Output:", masked_cpf)  

# Output: "123.***.**9-01"

2. Masking CNPJ

The CNPJ format consists of 14 digits. Maskify will retain the first two and last two digits, masking the middle portion:

from maskify.masker import Masker

cnpj = "12.345.678/0001-99"
masked_cnpj = Masker.mask_cnpj(cnpj, "*")
print("Output:", masked_cnpj)  

# Output: "12.***.***/**01-99"

3. Masking email

The email masking function hides a portion of the local part of the email (before @), leaving the first and last characters visible:

from maskify.masker import Masker

email = "usuario@exemplo.com"
masked_email = Masker.mask_email(email, "*")
print("Output:", masked_email)  

# Output: "u*****o@exemplo.com"

4. Masking credit card

Maskify supports multiple credit card formats, including standard 16-digit cards, American Express (15 digits), and Diners Club (14 digits). It retains only the last four digits, masking the rest:

from maskify.masker import Masker

credit_card = "1234 1234 1234 1234"
masked_credit_card = Masker.mask_credit_card(credit_card, "*")
print("Output:", masked_credit_card)  

# Output: "**** **** **** 1234"

5. Masking mobile phone numbers

Mobile phone numbers with 11 digits are masked to display only the area code, first digit, and last four digits:

from maskify.masker import Masker

mobile_phone = "(11) 91234-5678"
masked_mobile_phone = Masker.mask_mobile_phone(mobile_phone)
print("Output:", masked_mobile_phone)  

# Output: "(11) *****-5678"

6. Masking residential phone numbers

Residential phone numbers with 10 digits are masked to display only the area code, first two digits, and last four digits:

from maskify.masker import Masker

residential_phone = "(11) 1234-5678"
masked_residential_phone = Masker.mask_residential_phone(residential_phone)
print("Output:", masked_residential_phone)  

# Output: "(11) ****-5678"

7. Custom Masking

Maskify provides a general mask function to apply a mask to any string. Specify the start position, length of the mask, and masking character:

from maskify.masker import Masker

text = "Confidential"
masked_text = Masker.mask(text, start_position=2, length=8)
print("Output:", masked_text)  

# Output: "Co********al"

Error Handling

If input values do not meet format requirements, Maskify functions raise a ValueError with a descriptive message. Ensure that inputs are in the expected format (e.g., 11 digits for CPF, 14 digits for CNPJ) to avoid exceptions.

Contributing

We welcome contributions to enhance Maskify! Feel free to submit issues or pull requests. For major changes, please open a discussion first to share your proposed changes.

License

This project is licensed under the MIT License.

Metadata

Release files for maskify-py 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maskify-py 0.1.2
File Size Uploaded
maskify_py-0.1.2.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for maskify-py 0.1.2
File Interpreter ABI Platform
maskify_py-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / maskify_py-0.1.2.tar.gz

Download URL maskify_py-0.1.2.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8b63834f83190b3c1f28430f3d36827d6492c8abac7cd9a60ab8594319b09a0d
BLAKE2b-256 checksum
How to use checksums
88e1caa555b351256d5e3bd3b8b40ee52e44b7db54b8864f2b20c2676dc6eec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / maskify_py-0.1.2-py3-none-any.whl

Download URL maskify_py-0.1.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
812d193c7b3efc55465868ce205c07b13f5d606ed1a8cba0dee4078a67130770
BLAKE2b-256 checksum
How to use checksums
1e1b1656ec02178d6c0136440ac9b44a5f914e3831ae241e6a4eb3d412aa1b0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page