Skip to main content

Python SDK for calling the ProxyML API

Project description

proxyml

Python SDK for the ProxyML API.

Status: Early access — server endpoints coming soon.
Request early access or star this repo to follow progress.

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

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
proxyml.put_schema(schema)

# 3. Generate synthetic training data
synth_df = proxyml.synthesize_data(num_points=500)

# 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),
)

# 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/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.

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) Generate a schema dict from a DataFrame
put_schema(schema) Upload a schema to the API
synthesize_data(num_points, sample, as_df) Generate synthetic data points
train_surrogate(samples, predictions, feature_names, task, test_size) Train a surrogate model
predict(samples, version) Score samples with the surrogate model
find_counterfactual(sample, target, ...) Find a counterfactual for a given sample
interpret_counterfactual(sample, counterfactual, ...) Generate a human-readable explanation

Full documentation: docs/api.md

Examples

License

Apache 2.0 — see LICENSE.

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

proxyml-0.1.4.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

proxyml-0.1.4-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file proxyml-0.1.4.tar.gz.

File metadata

  • Download URL: proxyml-0.1.4.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for proxyml-0.1.4.tar.gz
Algorithm Hash digest
SHA256 242b1e713dd23ceaf3a569c96ef9432407c2c50299c847f4f52b415c9ccf1464
MD5 8ff5c74577ca25ebd94e1bf5c1208501
BLAKE2b-256 bbbd1cc1784c1b116debff79c5c287e2369f30f6843d1ab324c26f019bc89428

See more details on using hashes here.

File details

Details for the file proxyml-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: proxyml-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for proxyml-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c78db03ae1a1af4b40057fca9afa28894e580babe2498dede844d5ede0ac718b
MD5 00d0db436cecaee3cbdac58c6a1e236d
BLAKE2b-256 73865652f88ff42d143017a32e774619f41c6a98075c83920576ee8fb4c4bc3e

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