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

python_dp-1.1.3rc6-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

python_dp-1.1.3rc6-cp310-cp310-macosx_10_14_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10 macOS 10.14+ x86-64

python_dp-1.1.3rc6-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

python_dp-1.1.3rc6-cp39-cp39-macosx_10_14_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

python_dp-1.1.3rc6-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_dp-1.1.3rc6-cp38-cp38-macosx_10_14_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

python_dp-1.1.3rc6-cp37-cp37m-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.7m Windows x86-64

python_dp-1.1.3rc6-cp37-cp37m-macosx_10_14_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

Details for the file python_dp-1.1.3rc6-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 210fc48509eeeb06a29fcd855c194f8df8423cd6cfb1dd0ffaee9a94d14e064a
MD5 3461db921034ea9276d8e064a6ab1d81
BLAKE2b-256 ef29021e06ac922d0d8e80c29c6a1a988f31082e3856cc7b499ac74566f5a951

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d7a9a0fc26b45895ee07eba9732f83139a9332f0734b626aabca32ce95f5f4f0
MD5 6c3436a059a938b70816023801915d01
BLAKE2b-256 501a779be928b66a98e44fb1d1b719899425494879007ca45ee5bf4c83dea262

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 09b60090221f256fb78aebd9a81c0652024ee1adfd12a30197f8b4952b8a84d4
MD5 e4d4827c724682c24f8bd2d7154c835d
BLAKE2b-256 f57854616a326004ddecf742211b6ba57d7e075ae5d51da77735ae47854d68a2

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 93818ab42e8c39f71e6d60066ddc629232e5f8978bbae06be9f78460e0831109
MD5 d8bc47ce5d45e0904d8c0aaf4e95f01a
BLAKE2b-256 59ec2ab4bcd25b5b0c9dd70477c304d6733bcbc66874687d6bf654e0f960e7a4

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9950973d3966cbada54f7626db18c8e3e4a11a3c63cd1b63453e7af9802b2a20
MD5 1f8c560bbe49868ce15fc9ead70f5471
BLAKE2b-256 e7fbd9ff7698a17a6511e840768aecc47bda02ffb93268dc0900e2b2e82d7fcf

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d74002c691a892db00611b062b81faca678f9bb4ec3416d4f8ae86d9ec083a9e
MD5 151041bedd0717936ca8ed481f4b72fd
BLAKE2b-256 ece8096543389a75bfeebc18b7e7d726e7c1e88ddb1587f487105456e5b4b36b

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 713698d3e0e748b01f8f4f65f986928a0e0b8276518b867fad2d6addaa9ae88a
MD5 42c80a1b72a6123b48d661b1b8c0869c
BLAKE2b-256 2545778c57e07e5356fafea18f4a4eff44112a351f4239eabf87a1489807eda5

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc6-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc6-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 10da035ea2a2ccb3317f108870e6058c0d5f3769f82b07ea030d1e4e6562c77d
MD5 ae9981c3267bc1d73dd6704158bbe984
BLAKE2b-256 6daf1bfa5730e62f375c1f77ad7a2c3c8b363cf8bbd6dd6e9e3ec8f9160b83a1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page