proxyml
Python SDK for the ProxyML API.
Why ProxyML?
Most explainability tools require sending your data to a third-party server. ProxyML never sees your training data. You generate synthetic data locally, score it with your own model, and only the surrogate model and summary statistics are uploaded — your data stays yours.
Installation
pip install proxyml
Want to train a challenger model locally, with no round-trip to the API? Install the local extra (adds scikit-learn and scipy):
pip install 'proxyml[local]'
Setup
ProxyML requires an API key. Set it as an environment variable before importing the package:
export PROXYML_API_KEY="your-api-key"
Optionally override the base URL (defaults to https://api.proxyml.ai/api/v1):
export PROXYML_BASE_URL="https://api.proxyml.ai/api/v1"
Quick Start
import pandas as pd
import proxyml
from proxyml import get_schema
# 1. Load your dataset and generate a schema
df = pd.read_csv("data.csv")
schema = get_schema(df, immutable_cols=["age", "gender"])
# 2. Upload the schema under a name — synthesis and training reference it by name
SCHEMA_NAME = "my_schema"
proxyml.put_schema(schema, name=SCHEMA_NAME)
# 3. Generate synthetic training data
synth_df = proxyml.synthesize_data(num_points=500, schema_name=SCHEMA_NAME)
# 4. Score synthetic data with your black-box model
predictions = my_model.predict(synth_df.values.tolist())
# 5. Train a surrogate model
proxyml.train_surrogate(
samples=synth_df.values.tolist(),
predictions=predictions,
feature_names=list(synth_df.columns),
schema_name=SCHEMA_NAME,
)
# 6. Find a counterfactual explanation
sample = df.iloc[0].tolist()
cf = proxyml.find_counterfactual(sample=sample, target=1, version=None)
if cf is not None:
original = synth_df.iloc[0].to_dict()
cf_dict = cf.iloc[0].to_dict()
current_pred = my_model.predict([sample])[0]
cf_pred = my_model.predict([cf.values.tolist()[0]])[0]
explanation = proxyml.interpret_counterfactual(
sample=original,
counterfactual=cf_dict,
prediction_changed=(current_pred != cf_pred),
)
print(explanation)
See docs/challenger.md for the end-to-end challenger flow (train, upload, CI, PR comments), docs/quickstart.md for a full walkthrough and docs/api.md for complete API reference.
Core Concepts
Surrogate model — A fast, interpretable model trained to approximate your black-box model's behavior on synthetic data. Once trained, it can be queried directly via the ProxyML API.
Challenger model — Trained the same way as a surrogate, but locally (proxyml.local, no round-trip to the API) and against either real ground-truth labels (a genuine challenger to compare against a champion model) or a black box's predictions (a surrogate/explainer). Its export is structurally identical to a server-trained surrogate's, so the two can be compared and scored with the exact same arithmetic.
Counterfactual explanation — Given a prediction, a counterfactual is the minimal change to input features that would produce a different prediction. It answers: "What would have to be different for the outcome to change?"
Schema — Describes the statistical properties of each feature (type, range, distribution). Used to generate realistic synthetic data and constrain counterfactual search.
API Reference
| Function | Description |
|---|---|
get_schema(df, immutable_cols) |
Infer a FeatureSchema from a DataFrame |
put_schema(schema, name) |
Upload a schema to the API under a name |
synthesize_data(num_points, sample, as_df, schema_name) |
Generate synthetic data points |
train_surrogate(samples, predictions, feature_names, task, test_size, schema_name) |
Train a surrogate model |
train_auto_surrogate(data, target_col, ...) |
Load data + train a surrogate in one call, skipping synthesis |
export_surrogate(version) |
Export a surrogate for offline scoring via predict_from_export |
predict(sample, version) |
Score a single sample with the surrogate model |
find_counterfactual(sample, target, ...) |
Find a counterfactual for a given sample |
interpret_counterfactual(sample, counterfactual, ...) |
Generate a human-readable explanation |
proxyml.local.train_challenger(df, target, schema, ...) |
Train a challenger model locally — no API round-trip (pip install 'proxyml[local]') |
proxyml.local.train_auto_challenger(data, target_col, ...) |
Load data + train a local challenger in one call |
upload_challenger(payload, ci_token=None) |
Upload a challenger comparison headlessly, e.g. from CI (PROXYML_CI_TOKEN, not PROXYML_API_KEY) |
get_challenger_summary(ci_token=None) |
Fetch a CI-ready summary of the latest challenger comparison |
check_data_drift(model_id, df, ...) |
Compare recent data against a model's training data (statistics only leave your machine); returns a pass/drift verdict |
list_drift_checks(model_id) / get_drift_check(model_id, snapshot_id) / delete_drift_check(model_id, snapshot_id) |
Browse or delete stored drift verdicts |
proxyml.ci.post_challenger_comment(...) |
Post/update a sticky PR comment with the challenger comparison |
Full documentation: docs/api.md
Examples
examples/basic_usage.py— Schema upload, data synthesis, surrogate trainingexamples/counterfactual_example.py— Counterfactual search and interpretationexamples/regression_example.py— Regression with immutable featuresexamples/multiclass_example.py— Multi-class classification with per-class feature importancesexamples/testing_example.py— Using a surrogate as a reference model in CIexamples/surrogate_export_example.py— Exporting a surrogate and reproducing its predictions locallyexamples/ci_challenger_example.py+examples/github_actions_challenger.yml— Training a challenger and posting the comparison as a PR comment from CIexamples/ci_data_drift_example.py+examples/github_actions_data_drift.yml— Nightly data drift check that fails the job when recent data has drifted from a model's training data
License
Apache 2.0 — see LICENSE.
Metadata
Release files for proxyml 0.12.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| proxyml-0.12.1.tar.gz | 45.9 kB | Without provenance | Details for proxyml-0.12.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| proxyml-0.12.1-py3-none-any.whl | Python 3 | none | any | Details for proxyml-0.12.1-py3-none-any.whl |
Total release size: 77.2 kB
Release files / proxyml-0.12.1.tar.gz
| Download URL | proxyml-0.12.1.tar.gz |
|---|---|
| Size | 45.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f56947f408f5e7cf59f951eb5bee4885f78df015cbd09a762370fcc799aeb843
|
|
BLAKE2b-256 checksum How to use checksums |
d606a0af75646713a0eed7d88940b008f06c40afbfce4eefc3f014cb5883b52e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / proxyml-0.12.1-py3-none-any.whl
| Download URL | proxyml-0.12.1-py3-none-any.whl |
|---|---|
| Size | 31.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9515968c661e7fd8762c87c18762e41b46e036bb81d6d3e55d2c40c5b908df5d
|
|
BLAKE2b-256 checksum How to use checksums |
e80e637bd5aab4c4895043cb798dafa0fa692edbeac702db60122818556a10a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for proxyml 0.12.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.