Skip to main content

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.6+. Support for Python 3.5 and below is deprecated.

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
# Basic Structure: `BoundedMean(epsilon: float, lower_bound: Union[int, float, None], upper_bound: Union[int, float, None])`
# `epsilon`: a Double, between 0 and 1, denoting the privacy threshold,
#            measures the acceptable loss of privacy (with 0 meaning no loss is acceptable)
x = BoundedMean(epsilon=0.6, lower_bound=1, upper_bound=10)

# If the lower and upper bounds are not specified,
# PyDP automatically calculates these bounds
# x = BoundedMean(epsilon: float)
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 –>

License

Apache License 2.0

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

python_dp-1.1.5rc11-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5rc11-cp314-cp314-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 15.0+ universal2 (ARM64, x86-64)

python_dp-1.1.5rc11-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5rc11-cp313-cp313-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ universal2 (ARM64, x86-64)

python_dp-1.1.5rc11-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5rc11-cp312-cp312-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ universal2 (ARM64, x86-64)

python_dp-1.1.5rc11-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5rc11-cp311-cp311-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ universal2 (ARM64, x86-64)

File details

Details for the file python_dp-1.1.5rc11-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a08aabe26617d406b8a2073fca050a0169e7d24a3e2d338f9db73a0d1828bb05
MD5 2580385bb9504ff90c91b98fbfb822d8
BLAKE2b-256 6662b50e3b117f641adc506e4df38c62a3167c7be1337199acf46c288a7adb75

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp314-cp314-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp314-cp314-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 a6b28bdaaa57a2991cb6dcf9585f4841f987a4904d9c6f1c6b3d9289821a436e
MD5 67fb6d3a48b0663d0dd4fc633a7fed4e
BLAKE2b-256 8901217c3fd0a03d8359c9bb6056d151e0944dbbd335e9983072b6d1bed79730

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a11eac18bfb1e12632bc45a67ce70893abddf42ce91b17d0778ba1aead7b6afd
MD5 6bc31a0e0d0ae688590a11c680c3ffe8
BLAKE2b-256 186ebe4d1c00e604aaf0dd94d4ce408a150b7fa2dfbdb8acc37388e75ce79559

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp313-cp313-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp313-cp313-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 3b7a103c1aa141fbdfd1911eb265968812369f19735ff144d43935d2a60337d4
MD5 4182445e74520ef6a19dff5dd2fc5645
BLAKE2b-256 169d80ecc9d2f69b6fd7f3895e36b7e60c34e6584096f563d45a2c9fb8c6dba8

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1c756a35694222f257ea877c4484dfaf71c3cb3a806b6da8082a071f79349626
MD5 8095ea5617c69af0441b30b5eb0e77c8
BLAKE2b-256 4fbab20211ca09adb7f509eb5dd47b795e8d619191a4333d060cd3e7f4a17063

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp312-cp312-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp312-cp312-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 05002344685b6552cffca88a5290ea367ef53842661eb561ba393d597ab7cbcc
MD5 f91455a5b013f1e8718ea3b92fe7fd25
BLAKE2b-256 b37904579ac8f68ab3c23a544250e7b2b6b192164eecbc08fd585eec01a10457

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a654aea2b049daefb2da2e63d0be6303afc140b524ac7823de25092634d9af5b
MD5 15b911da91d6ecaac6c741a55f28346a
BLAKE2b-256 cc24f86a901dfd8f1b79f3c8513cff0a243731840d41a6269eb439c2263f5d6b

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc11-cp311-cp311-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc11-cp311-cp311-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 4f7e04084ee3cf59fd3cab9cdf75c467bbd2888780339a279fd985268430a7cc
MD5 ed3a6bc2404545d99d6515438e99dc9e
BLAKE2b-256 e61b6dd459e83a407d1733fc669d2aafb640a051b1856bdcd3bad3b5cfc7d641

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