DEV Community

Vishnu Sharma
Vishnu Sharma

Posted on

πŸ”’ Stop Exposing Emails, Phones & Cards in Logs β€” Meet `validata-py`

πŸš€ I Built validata-py β€” A Lightweight Python Library for Masking Sensitive Data

While building backend systems, APIs, logging pipelines, and debugging tools, I kept running into the same problem:

Sensitive data was everywhere.

  • Phone numbers inside logs
  • Emails inside payloads
  • Card numbers in debug responses
  • PII leaking into monitoring systems
  • Raw customer data showing up during development

Every project ended up with custom masking utilities scattered across the codebase.

Some libraries handled emails.
Some handled cards.
Some only worked for regex scrubbing.

Nothing felt unified.

So I built validata-py β€” a lightweight Python package focused on one thing:

Simple, consistent, production-ready data masking.


✨ What is validata-py?

validata-py is a lightweight privacy-focused utility library for:

βœ… Email masking
βœ… Phone masking
βœ… Card masking
βœ… Payload anonymization
βœ… Regex-based PII scrubbing
βœ… CPF/CNPJ masking
βœ… Generic string concealment

All with:

  • One import
  • One class
  • Zero dependencies
  • Clean API design

πŸ“¦ Installation

pip install validata-py
Enter fullscreen mode Exit fullscreen mode

⚑ Quick Example

from validata_py import Veil

# Email masking
Veil.shield_email("alice@example.com")
# a****@e******.com

# Phone masking
Veil.shield_phone("+91 98765-43210")
# +91 *****-3210

# Card masking
Veil.shield_card("4111 1111 1111 1111")
# **** **** **** 1111

# PII scrubbing
Veil.scrub_text(
    "Contact me at dev@example.com or 9876543210"
)

# Contact me at [EMAIL] or [PHONE]
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ One of My Favorite Features β€” Payload Masking

This became extremely useful while logging API payloads safely.

from validata_py import Veil

payload = {
    "name": "Priya Sharma",
    "email": "priya@example.com",
    "mobile": "+91-98765-43210",
    "salary": 950000,
}

blueprint = {
    "name": "text",
    "email": "email",
    "mobile": "phone",
    "salary": "zero",
}

Veil.shield_payload(payload, blueprint)
Enter fullscreen mode Exit fullscreen mode

Output:

{
    "name": "P**********a",
    "email": "p****@e******.com",
    "mobile": "+91-*****-3210",
    "salary": 0
}
Enter fullscreen mode Exit fullscreen mode

🧠 Why I Built It

I wanted a package that was:

  • Lightweight
  • Easy to use
  • Dependency-free
  • Consistent
  • Production-friendly
  • Formatting-safe

For example:

Veil.shield_phone("+91 98765-43210")
Enter fullscreen mode Exit fullscreen mode

preserves formatting automatically instead of returning broken unreadable strings.


πŸ›  Useful For

  • Backend APIs
  • Logging systems
  • GDPR/privacy workflows
  • Audit pipelines
  • Debug payload sanitization
  • Security tooling
  • Internal admin dashboards
  • Data anonymization

πŸ’‘ Features

πŸ”Ή Generic String Concealment

Veil.cover("secret-token", from_index=3)
# sec*********
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Email Masking

Veil.shield_email("alice@example.com")
# a****@e******.com
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Phone Masking

Veil.shield_phone("+91 98765-43210")
# +91 *****-3210
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Card Masking

Veil.shield_card("4111 1111 1111 1111")
# **** **** **** 1111
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Free-Text PII Detection

Veil.scrub_text(
    "Call me at john@example.com"
)

# Call me at [EMAIL]
Enter fullscreen mode Exit fullscreen mode

πŸš€ Future Improvements

Some ideas I’m exploring:

  • PAN masking
  • Aadhaar masking
  • IBAN masking
  • Custom regex strategies
  • Async processing
  • FastAPI middleware integration
  • Structured log sanitizers

Would love ideas from the community.


πŸ”— Links

GitHub

https://github.com/vishnusharma511/validata-py

PyPI

https://pypi.org/project/validata-py/


❀️ Feedback Welcome

This is an early open-source release, and I’d genuinely love:

  • Feedback
  • Feature ideas
  • Bug reports
  • Contributions
  • Performance suggestions

If you work with APIs, logs, privacy tooling, or security systems, I’d love to hear how you would use it πŸš€

Top comments (0)