Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Python API for Google's Differential Privacy library

Project description

Tests Version License

Introduction to PyDP

In today’s data-driven world, more and more researchers and data scientists use machine learning to create better models or more innovative solutions for a better future.

These models often tend to handle sensitive or personal data, which can cause privacy issues. For example, some AI models can memorize details about the data they’ve been trained on and could potentially leak these details later on.

To help measure sensitive data leakage and reduce the possibility of it happening, there is a mathematical framework called differential privacy.

In 2020, OpenMined created a Python wrapper for Google’s Differential Privacy project called PyDP. The library provides a set of ε-differentially private algorithms, which can be used to produce aggregate statistics over numeric data sets containing private or sensitive information. Therefore, with PyDP you can control the privacy guarantee and accuracy of your model written in Python.

Things to remember about PyDP:

  • ::rocket: Features differentially private algorithms including: BoundedMean, BoundedSum, Max, Count Above, Percentile, Min, Median, etc.
  • All the computation methods mentioned above use Laplace noise only (other noise mechanisms will be added soon! :smiley:).
  • ::fire: Currently supports Linux and macOS (Windows support coming soon :smiley:)
  • ::star: Use Python 3.x.

Installation

To install PyDP, use the PiPy package manager:

pip install python-dp

(If you have pip3 separately for Python 3.x, use pip3 install python-dp.)

Examples

Refer to the curated list of tutorials and sample code to learn more about the PyDP library.

You can also get started with an introduction to PyDP (a Jupyter notebook) and the carrots demo (a Python file).

Example: calculate the Bounded Mean

# Import PyDP
import pydp as dp
# Import the Bounded Mean algorithm
from pydp.algorithms.laplacian import BoundedMean

# Calculate the Bounded Mean
# Structure: `BoundedMean(epsilon: double, lower: int, upper: int)`
# `epsilon`: a Double, between 0 and 1, denoting the privacy threshold,
#            measures the acceptable loss of privacy (with 0 meaning no loss is acceptable)
# `lower` and `upper`: Integers, representing lower and upper bounds, respectively
x = BoundedMean(0.6, 1, 10)

# If the lower and upper bounds are not specified,
# PyDP automatically calculates these bounds
# x = BoundedMean(epsilon: double)
x = BoundedMean(0.6)

# Calculate the result
# Currently supported data types are integers and floats
# Future versions will support additional data types
# (Refer to https://github.com/OpenMined/PyDP/blob/dev/examples/carrots.py)
x.quick_result(input_data: list)

Learning Resources

Go to resources to learn more about differential privacy.

Support and Community on Slack

If you have questions about the PyDP library, join OpenMined’s Slack and check the #lib_pydp channel. To follow the code source changes, join #code_dp_python.

Contributing

To contribute to the PyDP project, read the guidelines.

Pull requests are welcome. If you want to introduce major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

<!– ## Contributors –>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-dp, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size python_dp-1.0.1-cp35-cp35m-macosx_10_15_x86_64.whl (3.1 MB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size python_dp-1.0.1-cp35-cp35m-manylinux1_x86_64.whl (3.0 MB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size python_dp-1.0.1-cp35-cp35m-win_amd64.whl (1.6 MB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size python_dp-1.0.1-cp36-cp36m-macosx_10_15_x86_64.whl (3.1 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size python_dp-1.0.1-cp36-cp36m-manylinux1_x86_64.whl (3.0 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size python_dp-1.0.1-cp36-cp36m-win_amd64.whl (1.6 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size python_dp-1.0.1-cp37-cp37m-macosx_10_15_x86_64.whl (3.1 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size python_dp-1.0.1-cp37-cp37m-manylinux1_x86_64.whl (3.0 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size python_dp-1.0.1-cp37-cp37m-win_amd64.whl (1.6 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size python_dp-1.0.1-cp38-cp38-macosx_10_15_x86_64.whl (3.1 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size python_dp-1.0.1-cp38-cp38-manylinux1_x86_64.whl (3.0 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size python_dp-1.0.1-cp38-cp38-win_amd64.whl (1.6 MB) File type Wheel Python version cp38 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page