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.1.tar.gz (651.1 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.1-py3-none-any.whl (55.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: valencity-0.1.1.tar.gz
  • Upload date:
  • Size: 651.1 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.1.tar.gz
Algorithm Hash digest
SHA256 d5265415040017364944d05154252aefd294b49ecb1ed8b40676618a17e1f379
MD5 1356a0af114ef642a63293de4ea81333
BLAKE2b-256 aaaa03bbeccea138a77ffc04a63fc81dd7570ca49af26eecdd9f8f31bff84b61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: valencity-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 55.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 780d3ed487455ddbc16b9887903bb800ecf255da872ff536930b652018ee8cb5
MD5 b1ff324e4f21442a439f75d47b567f4c
BLAKE2b-256 1e218bdf4a38200b35cdfe26f142a4f50d88b3bfea5687c715bec7f650a416c6

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