This documentation is for an old version of OpenDP.

The current release of OpenDP is v0.11.1.

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.

>>> space = (dp.atom_domain(T=float), dp.absolute_distance(T=float))
>>> laplace_mechanism = space >> 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 demonstrates a number of low-level OpenDP patterns:

  • First, define your “metric space”: a data domain and a definition of distance.

  • Then, chain operators together to construct a Measurement (aka mechanism).

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

OpenDP has two APIs and we’ll demonstrate how to use both:

  • The Context API is simpler and helps to enforce best practices. Currently available only for Python.

  • The Framework API is lower-level. Available for Python, R and Rust, it directly implements the OpenDP Programming Framework.

Because the Context API is a wrapper around the Framework API, it is easier to use but less flexible: All calls ultimately pass through the Framework API.

The next page will demonstrate usage of the Context API in Python, and Framework API in Python and R. After that, the remaining “Getting Started” documentation will focus just on Python.