Skip to main content

SecureML Logo

CI/CD Status Tests Status PyPI Version License Python Versions

Documentation

SecureML is an open-source Python library that integrates with popular machine learning frameworks like TensorFlow and PyTorch. It provides developers with easy-to-use utilities to ensure that AI agents handle sensitive data in compliance with data protection regulations.

Key Features

  • Data Anonymization Utilities:
    • K-anonymity implementation with adaptive generalization
    • Pseudonymization with format-preserving encryption
    • Configurable data masking with statistical property preservation
    • Hierarchical data generalization with taxonomy support
    • Automatic sensitive data detection
  • Privacy-Preserving Training Methods:
    • Differential privacy integration with PyTorch (via Opacus) and TensorFlow (via TF Privacy)
    • Federated learning with Flower, allowing training on distributed data without centralization
    • Support for secure aggregation and privacy-preserving federated learning
  • Compliance Checkers: Tools to analyze datasets and model configurations for potential privacy risks
  • Synthetic Data Generation:
    • Multiple generation methods including statistical modeling, GANs, and copulas
    • SDV integration with Gaussian Copula, CTGAN, and TVAE synthesizers
    • Automatic sensitive data detection and special handling
    • Preservation of statistical properties and correlations between variables
    • Support for mixed data types (numeric, categorical, datetime)
    • Configurable privacy-utility tradeoff controls
    • Tabular data synthesis with relation preservation
  • Regulation-Specific Presets:
    • Pre-configured YAML settings aligned with major regulations (GDPR, CCPA, HIPAA, LGPD)
    • Detailed compliance requirements for each regulation
    • Customizable identifiers for personal data and sensitive information
    • Integration with compliance checking functionality
  • Audit Trails and Reporting:
    • Comprehensive audit logging of data access, transformations, and model operations
    • Detailed event tracking for privacy-related operations with timestamps and contexts
    • Function-level auditing through decorators
    • Automated compliance reports in HTML and PDF formats
    • Visual dashboards with charts showing privacy metrics and event distributions
    • Integration with compliance checkers for continuous monitoring

Installation

With pip (Python 3.11-3.12):

pip install secureml

Optional Dependencies

# For generating PDF reports for compliance and audit trails
pip install secureml[pdf]

# For secure key management with HashiCorp Vault
pip install secureml[vault]

# For all optional components
pip install secureml[pdf,vault]

Quick Start

Data Anonymization

Anonymizing a dataset to comply with privacy regulations:

import pandas as pd
from secureml import anonymize

# Load your dataset
data = pd.DataFrame({
    "name": ["John Doe", "Jane Smith", "Bob Johnson"],
    "age": [32, 45, 28],
    "email": ["john.doe@example.com", "jane.smith@example.com", "bob.j@example.com"],
    "ssn": ["123-45-6789", "987-65-4321", "456-78-9012"],
    "zip_code": ["10001", "94107", "60601"],
    "income": [75000, 82000, 65000]
})
    
# Anonymize using k-anonymity
anonymized_data = anonymize(
    data,
    method="k-anonymity",
    k=2,
        sensitive_columns=["name", "email", "ssn"]
    )
    
    print(anonymized_data)

Compliance Checking with Regulation Presets

SecureML includes built-in presets for major regulations (GDPR, CCPA, HIPAA, LGPD) that define the compliance requirements specific to each regulation:

import pandas as pd
from secureml import check_compliance
    
# Load your dataset
data = pd.read_csv("your_dataset.csv")
    
# Model configuration
model_config = {
    "model_type": "neural_network",
    "input_features": ["age", "income", "zip_code"],
    "output": "purchase_likelihood",
    "training_method": "standard_backprop"
}
    
# Check compliance with GDPR
report = check_compliance(   
    data=data,
    model_config=model_config,
    regulation="GDPR"
)
    
# View compliance issues
if report.has_issues():
    print("Compliance issues found:")
    for issue in report.issues:
        print(f"- {issue['component']}: {issue['issue']} ({issue['severity']})")
        print(f"  Recommendation: {issue['recommendation']}")

Privacy-Preserving Machine Learning

Train a model with differential privacy guarantees:

import torch.nn as nn
import pandas as pd
from secureml import differentially_private_train
    
# Create a simple PyTorch model
model = nn.Sequential(
    nn.Linear(10, 64),
    nn.ReLU(),
    nn.Linear(64, 2),
    nn.Softmax(dim=1)
)
    
# Load your dataset
data = pd.read_csv("your_dataset.csv")
    
# Train with differential privacy
private_model = differentially_private_train(
    model=model,
    data=data,
    epsilon=1.0,  # Privacy budget
    delta=1e-5,   # Privacy delta parameter
    epochs=10,
    batch_size=64
)

Synthetic Data Generation

Generate synthetic data that maintains the statistical properties of the original data:

import pandas as pd
from secureml import generate_synthetic_data
    
# Load your dataset
data = pd.read_csv("your_dataset.csv")
    
# Generate synthetic data
synthetic_data = generate_synthetic_data(
    template=data,
    num_samples=1000,
    method="statistical",  # Options: simple, statistical, sdv-copula, gan
    sensitive_columns=["name", "email", "ssn"]
)
    
print(synthetic_data.head())

Documentation

For detailed documentation, examples, and API reference, visit our documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or Issue. Our focus is expanding supported legislations beyond GDPR, CCPA, HIPAA, and LGPD. You can help us with that!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for secureml 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secureml 0.3.1
File Size Uploaded Provenance
secureml-0.3.1.tar.gz 87.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for secureml 0.3.1
File Interpreter ABI Platform
secureml-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 180.6 kB

Release files / secureml-0.3.1.tar.gz

Download URL secureml-0.3.1.tar.gz
Size 87.1 kB
Tags Source
SHA-256 checksum
How to use checksums
48db7f79b0986eb65d5e5679d166eae0b87fde509ce9738a8e91b0487bc09bba
BLAKE2b-256 checksum
How to use checksums
2a5d06158e78521e8388b11cf59fe45c2960b8c96d487ff53d642626f095e816
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.13 Linux/6.11.0-1015-azure

Release files / secureml-0.3.1-py3-none-any.whl

Download URL secureml-0.3.1-py3-none-any.whl
Size 93.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c86827cbe22fce8d4e07a5d3be6add0245abcddcf38ea9be4add464abd6d266
BLAKE2b-256 checksum
How to use checksums
a8620fdfe6d63958eb801f5cad2c77e673ebe63ccbdbcab3d7fb78114e0aba99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.13 Linux/6.11.0-1015-azure

Security for secureml 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page