Skip to main content

๐Ÿ” privacylens

Audit any ML model for privacy vulnerabilities โ€” in 3 lines of code.

CI Coverage PyPI version Python Discussions License: MIT PRs Welcome


๐ŸŽฏ What is privacylens?

Most ML engineers don't know if their model is leaking private training data. privacylens audits it across 5 core privacy vulnerability vectors.

from privacylens import audit

report = audit(model, X_train, y_train, X_test)
report.summary()

# Export HTML Compliance Report for GDPR/HIPAA sharing
report.to_html("audit_report.html")
+-------------------------------------------------------------------+
|             privacylens โ€” 5-Point Privacy Audit Report            |
+------------------------------------+--------------+---------------+
| Check                              | Score        | Risk          |
+------------------------------------+--------------+---------------+
| Membership Inference Attack        | 0.087        | LOW           |
| PII Leakage Detection              | 0.000        | LOW           |
| Model Inversion Risk               | 0.042        | LOW           |
| Attribute Inference Risk           | 0.015        | LOW           |
| Differential Privacy (ฮต)           | 0.038        | LOW           |
+------------------------------------+--------------+---------------+

Model: RandomForestClassifier
Overall Risk: LOW

โ€ข MIA advantage score: 0.087 โ€” model shows low Membership Inference vulnerability.
โ€ข PII leakage score: 0.000 โ€” model shows low PII Leakage vulnerability.
โ€ข Model Inversion score: 0.042 โ€” model shows low Model Inversion vulnerability.
โ€ข Attribute Inference score: 0.015 โ€” model shows low Attribute Inference vulnerability.
โ€ข Differential Privacy score: 0.038 โ€” model shows low Differential Privacy vulnerability.

โœจ 5-Point Privacy Audit Suite

  • ๐Ÿ•ต๏ธ 1. Membership Inference Attack (MIA) โ€” Detect if an attacker can identify training records using shadow model estimation (Shokri et al., 2017)
  • ๐Ÿ”Ž 2. PII Leakage Detection โ€” Scan predictions and samples for memorized PII (Emails, SSNs, Credit Cards, Phones, IPs)
  • ๐Ÿ”„ 3. Model Inversion Risk Scorer โ€” Evaluate feature reconstructability risk from confidence probabilities (Fredrikson et al., 2015)
  • ๐ŸŽฏ 4. Attribute Inference Attack โ€” Measure sensitive secondary attribute predictability from confidence vectors (Yeom et al., 2018)
  • ๐Ÿ›ก๏ธ 5. Differential Privacy (ฮต) Estimator โ€” Estimate empirical privacy loss ($\epsilon$) under single-record modifications (Jagielski et al., 2020)
  • ๐ŸŒ Native Framework Adapters โ€” Out-of-the-box support for scikit-learn, PyTorch (nn.Module), XGBoost, and HuggingFace Transformers
  • ๐Ÿ“„ HTML Compliance Reports โ€” Export standalone, interactive HTML reports (--report audit.html) for security & GDPR/HIPAA compliance sharing
  • ๐Ÿค– CLI + Python API โ€” Use in scripts or integrate into CI/CD pipelines (privacylens audit)
  • ๐Ÿ“Š JSON output โ€” Machine-readable results for dashboards and reporting (--output json)

๐Ÿ“ฆ Installation

# Base install (scikit-learn models)
pip install privacyaudit

# With PyTorch support
pip install "privacyaudit[torch]"

# With XGBoost support
pip install "privacyaudit[xgboost]"

# Everything (PyTorch, XGBoost, Transformers)
pip install "privacyaudit[all]"

Note: The PyPI package is privacyaudit. Import in Python as from privacylens import audit.


๐Ÿš€ Quick Start

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from privacylens import audit

# Train a model
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)

# Audit it for all 5 privacy vulnerabilities
report = audit(model, X_train, y_train, X_test, y_test)
report.summary()

# Export interactive HTML audit report
report.to_html("compliance_report.html")

# Get audit results as dict (for JSON logging or API responses)
print(report.to_dict())

๐Ÿ–ฅ๏ธ CLI Usage

# Audit a saved model file
privacylens audit model.pkl train.csv test.csv

# Export interactive HTML report
privacylens audit model.pkl train.csv test.csv --report compliance.html

# Output JSON for CI/CD integration
privacylens audit model.pkl train.csv test.csv --output json

# Skip MIA check in fast pipelines
privacylens audit model.pkl train.csv test.csv --no-mia

๐Ÿ—๏ธ Architecture

privacylens/
โ”œโ”€โ”€ src/privacylens/
โ”‚   โ”œโ”€โ”€ __init__.py         # Public API: audit(), AuditReport, Auditors, Adapters
โ”‚   โ”œโ”€โ”€ auditor.py          # Core 5-point orchestrator
โ”‚   โ”œโ”€โ”€ adapters/
โ”‚   โ”‚   โ”œโ”€โ”€ base.py         # BaseModelAdapter & get_adapter() factory
โ”‚   โ”‚   โ”œโ”€โ”€ sklearn_adapter.py
โ”‚   โ”‚   โ”œโ”€โ”€ pytorch_adapter.py
โ”‚   โ”‚   โ”œโ”€โ”€ xgboost_adapter.py
โ”‚   โ”‚   โ””โ”€โ”€ hf_adapter.py   # HuggingFace Transformers Adapter
โ”‚   โ”œโ”€โ”€ attacks/
โ”‚   โ”‚   โ”œโ”€โ”€ membership.py   # MIA engine (Shokri et al.)
โ”‚   โ”‚   โ”œโ”€โ”€ inversion.py    # Model Inversion Risk Auditor (Fredrikson et al.)
โ”‚   โ”‚   โ””โ”€โ”€ attribute.py    # Attribute Inference Auditor (Yeom et al.)
โ”‚   โ”œโ”€โ”€ leakage/
โ”‚   โ”‚   โ”œโ”€โ”€ pii.py          # PII Leakage Auditor (Regex + Severity Weighting)
โ”‚   โ”‚   โ””โ”€โ”€ dp.py           # Empirical Differential Privacy Epsilon Estimator
โ”‚   โ”œโ”€โ”€ report/
โ”‚   โ”‚   โ””โ”€โ”€ html.py         # HTML Compliance Report Generator (Jinja2)
โ”‚   โ””โ”€โ”€ cli.py              # Click CLI
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ benchmark_demo.py   # Enterprise Privacy Audit Benchmark
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ test_auditor.py
    โ”œโ”€โ”€ test_membership.py
    โ”œโ”€โ”€ test_pii_leakage.py
    โ”œโ”€โ”€ test_inversion.py
    โ”œโ”€โ”€ test_adapters.py
    โ”œโ”€โ”€ test_html_report.py
    โ”œโ”€โ”€ test_hf_adapter.py
    โ””โ”€โ”€ test_5point_audits.py

๐Ÿ“– Risk Score Interpretation

Check Score Risk Level Meaning
0.0 โ€“ 0.10 ๐ŸŸข LOW Model reveals minimal membership/PII/inversion information
0.10 โ€“ 0.30 ๐ŸŸก MEDIUM Moderate risk โ€” review training data exposure
0.30 โ€“ 1.00 ๐Ÿ”ด HIGH Model likely memorising sensitive training data

๐Ÿค Contributing

See CONTRIBUTING.md. All contributions welcome!

๐Ÿ“„ License

MIT โ€” see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

privacyaudit-1.0.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

privacyaudit-1.0.1-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file privacyaudit-1.0.1.tar.gz.

File metadata

  • Download URL: privacyaudit-1.0.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for privacyaudit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f8f586efa3ee9db2ee74f797adf7a547d454072066bbe83e5151a3e342342be7
MD5 cddc39b650ba4b31b40bd3a8fddfabe9
BLAKE2b-256 8692fb7953cbe1ed49ecf82e9df3ba356376e03047ea32bf857530d8b7288c71

See more details on using hashes here.

Provenance

The following attestation bundles were made for privacyaudit-1.0.1.tar.gz:

Publisher: release.yml on nithin42/privacylens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file privacyaudit-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: privacyaudit-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for privacyaudit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6182f450c178e1fcd76a10f06756b798a4c3f6cd3df3675c75fc90882e576baf
MD5 9d72bb9548e68948d0783e7bbdfb1e1b
BLAKE2b-256 3ef690a1e2d4bec6c5f6d92cd262c1b7853962e554dbb96f27411114e272be9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for privacyaudit-1.0.1-py3-none-any.whl:

Publisher: release.yml on nithin42/privacylens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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