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, nan=False
... ), dp.absolute_distance(T=float)
>>> laplace_mechanism = space >> dp.m.then_laplace(scale=1.0)
>>> dp_value = laplace_mechanism(123.0)
space <- c(atom_domain(.T = "f64", nan = FALSE), 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::<f64>::new_non_nan(), AbsoluteDistance::<f64>::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 the core of OpenDP, but in practice you may use the higher-level Context API.