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.

from privacylens import audit

report = audit(model, X_train, y_train, X_test)
report.summary()
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚             ๐Ÿ” privacylens โ€” Privacy Audit Report            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Check                        โ”‚ Score      โ”‚ Risk            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Membership Inference Attack  โ”‚ 0.087      โ”‚ LOW             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Model: RandomForestClassifier
Overall Risk: LOW

โ€ข MIA advantage score: 0.087 โ€” model shows low Membership Inference vulnerability.

โœจ Features

  • ๐Ÿ•ต๏ธ Membership Inference Attack (MIA) โ€” Detect if an attacker can identify training records using a shadow model approach (Shokri et al., 2017)
  • ๐ŸŒ Framework agnostic โ€” Works with scikit-learn, XGBoost, and any model with predict_proba()
  • ๐ŸŽจ Beautiful terminal output โ€” Rich colour-coded risk tables with LOW / MEDIUM / HIGH classification
  • ๐Ÿค– CLI + Python API โ€” Use in scripts or integrate into CI/CD pipelines
  • ๐Ÿ“Š JSON output โ€” Machine-readable results for dashboards and reporting

Coming in future releases:

  • ๐Ÿ”ข PII leakage detection in model embeddings
  • ๐Ÿ”„ Model inversion risk scoring
  • ๐Ÿค— HuggingFace Transformers adapter
  • ๐Ÿ“„ HTML compliance report export

๐Ÿ“ฆ Installation

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

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

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

# Everything
pip install "privacyaudit[all]"

Note: The PyPI package is privacyaudit. Import 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 privacy vulnerabilities
report = audit(model, X_train, y_train, X_test, y_test)
report.summary()

# Get results as dict (for JSON logging)
print(report.to_dict())

๐Ÿ–ฅ๏ธ CLI Usage

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

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

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

๐Ÿ—๏ธ Architecture

privacylens/
โ”œโ”€โ”€ src/privacylens/
โ”‚   โ”œโ”€โ”€ __init__.py         # Public API: audit(), AuditReport
โ”‚   โ”œโ”€โ”€ auditor.py          # Main orchestrator
โ”‚   โ”œโ”€โ”€ attacks/
โ”‚   โ”‚   โ””โ”€โ”€ membership.py   # MIA engine (shadow model + attack classifier)
โ”‚   โ””โ”€โ”€ cli.py              # Click CLI
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ test_auditor.py
    โ””โ”€โ”€ test_membership.py

๐Ÿ“– Risk Score Interpretation

MIA Score Risk Level Meaning
0.0 โ€“ 0.10 ๐ŸŸข LOW Model reveals minimal membership information
0.10 โ€“ 0.30 ๐ŸŸก MEDIUM Some memorisation risk โ€” review training data
0.30 โ€“ 1.00 ๐Ÿ”ด HIGH Model likely memorising training records

๐Ÿค 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-0.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

privacyaudit-0.2.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for privacyaudit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cf11c52c01d28584a5b2b18d948c9e697eb0cc59c66b04435d46ae20ebbc41d2
MD5 af79796eb8e92ba2b135132cec3ad288
BLAKE2b-256 a9d74728192b06cdef54a2e5ac812c29ab162f1d2916186291a8387ea42af270

See more details on using hashes here.

Provenance

The following attestation bundles were made for privacyaudit-0.2.0.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-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for privacyaudit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65845f9fd1daf7a76a562d42fb7ac883ddf4e6047e5061770dbdb25465b386f3
MD5 8bc939db2031501fb6161d7fad265372
BLAKE2b-256 9437a8709c69c2e3e46f4e388e80c8414ab1850d8e0c2760af422374b029c6e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for privacyaudit-0.2.0-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