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.5rc3-cp311-cp311-macosx_10_14_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.11 macOS 10.14+ x86-64

python_dp-1.1.5rc3-cp310-cp310-macosx_10_14_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10 macOS 10.14+ x86-64

python_dp-1.1.5rc3-cp39-cp39-macosx_10_14_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

python_dp-1.1.5rc3-cp38-cp38-macosx_10_14_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

File details

Details for the file python_dp-1.1.5rc3-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc3-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e331376fd1539d42dfc8e413db2727613318ef7a04a60c0649c7739f5eb6c1c7
MD5 798882790cfc16e624c9705a9175f18f
BLAKE2b-256 9c076bf08dc676b901402605eee03b67e8b2e28405fd3be92e6445b19e8dce52

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc3-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc3-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a5d9023252d56010692362658907f4660f9221856ee95de4434ac5ee51a97cea
MD5 4c86e42bef47cd2bb21e7c50a2745762
BLAKE2b-256 988c0072f2543c74d1dfbfbe6a8c4053e32d505eec68a397b67087e44661247d

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc3-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a53afbf52053f1d1cb245e5aeca404ce71a417812dc024e42d5ca4ad10729939
MD5 7bfe2a7809ab0a0b0ca95b73bc422187
BLAKE2b-256 2733441e14c2afea8259f8dad302945969feddeda6f3177572ae1389a6f5f251

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc3-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 336a9a139f082ca66b7b1a30f88a7a0fac9f69a88e1a0c8af150ecf8c22516b6
MD5 f5e54f028f1f69b05712b2f6a3334e17
BLAKE2b-256 87a6056702751a165865fee0afe2a81531213f847a612cdc055d26fe11ae636c

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