Skip to main content

A privacy & ML safety toolkit for production ML pipelines

Project description

🛡️ valencity

The ML Safety Fortress
Privacy Engineering • Data Validation • Leakage Prevention

PyPI version Python versions License: MIT Codecov Downloads

FeaturesInstallationQuick StartDocumentationContributing


🚀 Why valencity?

valencity is a comprehensive toolkit designed to make machine learning pipelines safer, compliant, and reliable. It bridges the gap between data engineering and privacy compliance, offering a "fortress" of protection for your data assets.

Feature valencity 🛡️ Great Expectations Pandera Custom Scripts
PII Detection ✅ 50+ Patterns ⚠️ Manual
Masking/Anonymization ✅ K-Anon, DP
Leakage Prevention ✅ Full Suite
Drift Detection ✅ 4+ Methods ⚠️ Manual
Safe Cross-Validation ✅ Built-in
HTML Reports ✅ Beautiful

✨ Features

🕵️ PII Detection & Anonymization

  • Detect 50+ types of PII including IBAN, Passports, and API Keys.
  • Smart Masking: Redact, hash, partial mask, or replace with fake data.
  • NLP Support: Named Entity Recognition for names and addresses (via spaCy).

✅ Data Validation & Quality

  • Drift Detection: Catch distribution shifts before they break your model.
  • Schema Validation: Enforce strict data contracts on your DFs.
  • Quality Checks: Nulls, duplicates, outliers, and cardinality.

🚫 Leakage Prevention

  • Safe Cross-Validation: Automatic leakage checks during CV.
  • Leakage Detectors: Find target leakage, train/test overlap, and temporal leakage.
  • Safe Splitters: Time-series and group-aware train/test splitting.

📦 Installation

# Install core package
pip install valencity

# Install with NLP support (for names/addresses)
pip install valencity[nlp]
python -m spacy download en_core_web_sm

⚡ Quick Start

1. Protect Your Data (PII)

import pandas as pd
from valencity.pii import PIIDetector, PIIMasker

# Scan for PII
df = pd.read_csv("users.csv")
detector = PIIDetector()
report = detector.scan_dataframe(df)

if report.has_pii:
    print(f"⚠️ Found PII in columns: {report.pii_columns}")

# Mask it
masker = PIIMasker(strategy="partial")  # j***@example.com
safe_df = masker.mask_dataframe(df)

2. Validate Quality & Drift

from valencity.validation import DriftDetector, DataSchema

# 1. Define expectations
schema = DataSchema.from_dataframe(train_df)

# 2. Check for drift in production
detector = DriftDetector(method="ks_test")
detector.fit(reference_df=train_df)

drift_report = detector.detect(current_df=new_data)
if drift_report.has_drift:
    print(f"🚨 Data drift detected using {drift_report.method}!")

3. Prevent Model Leakage

from valencity.leakage import SafeCrossValidator
from sklearn.linear_model import LogisticRegression

# Safe CV ensures preprocessing only sees training fold
# Prevents subtle data leakage bugs
cv = SafeCrossValidator(n_splits=5, preprocessor=StandardScaler())

scores = cv.cross_val_score(LogisticRegression(), X, y)
print(f"Realistic Accuracy: {scores.mean():.4f}")

🗺️ Roadmap

  • CLI Tool: valencity scan data.csv
  • Privacy Module: Differential Privacy & K-Anonymity
  • Synthetic Data: Generate safe, realistic test data
  • Integrations: MLflow, Airflow, and dbt support

🤝 Contributing

We welcome contributions! Please check out the Issues page.

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Built with ❤️ for the ML Community

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

valencity-0.1.0.tar.gz (650.4 kB view details)

Uploaded Source

Built Distribution

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

valencity-0.1.0-py3-none-any.whl (54.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for valencity-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3fb805033dc05b8f0d5fed05df6aa65e92825b8ed2b4d8d7a58f0a2d0c569879
MD5 fc72221d3b537ba998f0159dadcd7c1e
BLAKE2b-256 f8f810c35030171a673c6c64556fb5d39edd1116d35795d0047190df8b844abe

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for valencity-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86e75eaeaea56cbf760acc4ed1422a8346b3c18f9db8844db041a0e8853977ae
MD5 5f2a19fe7c0bf1e792c501191a6f9c62
BLAKE2b-256 b96612e38818dc52fcae65684e513492b061493df32235d1afc0ca2804857798

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