Quickstart#

OpenDP is available for Python, R, and Rust.

Use pip to install the opendp package from PyPI:

pip install opendp

First, make sure Rust is installed. (The R package includes Rust source code which will be compiled during install.)

Then, launch R and use install.packages:

install.packages('opendp', repos = 'https://opendp.r-universe.dev/')

In a new directory run cargo init and then specify OpenDP as a dependency in Cargo.toml:

[dependencies]
opendp = { features = ["contrib", "honest-but-curious"] }
# Optionally pin the version number.

This will make the OpenDP modules available to your local environment.

The vetting process is currently underway for the code in the OpenDP Library. Any code that has not completed the vetting process is marked as “contrib” and will not run unless you opt-in. Enable contrib globally with the following snippet:

>>> import opendp.prelude as dp
>>> dp.enable_features('contrib')

library(opendp)
enable_features("contrib")

In Rust, contrib is specified in Cargo.toml.

Once you’ve installed OpenDP, you can write your first program. Let’s apply Laplace noise to a value.

>>> laplace_mechanism = dp.space_of(float) >> dp.m.then_laplace(scale=1.)
>>> dp_value = laplace_mechanism(123.0)

space <- c(atom_domain(.T = "f64"), absolute_distance(.T = "f64"))
laplace_mechanism <- space |> then_laplace(1.)
dp_value <- laplace_mechanism(arg = 123.0)
use opendp::{
    domains::AtomDomain,
    error::Fallible,
    measurements::then_laplace,
    metrics::AbsoluteDistance,
};

fn main() -> Fallible<()> {
    let space = (AtomDomain::default(), AbsoluteDistance::default());
    let laplace_mechanism = (space >> then_laplace(1.0, None))?;
    let dp_value = laplace_mechanism.invoke(&123.0)?;
    println!("DP value: {}", dp_value);
    Ok(())
}

This is obviously not the easiest way to add noise to a number, but it demonstrates a number of OpenDP patterns:

  • Defining your metric space with space_of in Python’s Context API, or a (domain, distance) tuple in any language..

  • Chaining operators together with >> in Python and Rust, or |> in R.

  • Constructing a Measurement function on your metric space with then_laplace.

  • Invoking that measurement on a value to get a DP release.