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
# 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 –>

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.3rc2-cp39-cp39-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9

python_dp-1.1.3rc2-cp39-cp39-macosx_10_14_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

python_dp-1.1.3rc2-cp38-cp38-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_dp-1.1.3rc2-cp38-cp38-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8

python_dp-1.1.3rc2-cp38-cp38-macosx_10_14_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

python_dp-1.1.3rc2-cp37-cp37m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.7m Windows x86-64

python_dp-1.1.3rc2-cp37-cp37m-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.7m

python_dp-1.1.3rc2-cp37-cp37m-macosx_10_14_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

Details for the file python_dp-1.1.3rc2-cp39-cp39-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7d94c893b20108e81189fc424daabbdc7dde03f08c5451ddd0c38a65ce8dde1c
MD5 ab04e085f67b4cf0dcf8cec2183a553c
BLAKE2b-256 386067eec8c7c226f76277f320c2e0b0f2b308dd4d4a566c2dc8fdcdcd1c0a21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 7e7a9dad5d074dbcd6997ba6a2f16e74b4958469670b416db02540c9855f3684
MD5 8cba12d5fde656fa32d73738ea153065
BLAKE2b-256 9124706a3964cfb6566331d50a796de72d635ab64c232c1050531ee33abf5f0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2028f101a9d6c4e2e5fcd4f82c56d9e00a73e2680a9113ea9084b3bd4b4a7d43
MD5 8e0a26fdd89966bc489e9cf8623cf77b
BLAKE2b-256 5af7c0a3efa718149e72a0ddaa342d5dca89a6adf261b816ddbd00d783feb7bf

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0e6fc86910e2d61c3f7752f97bb3de53454fd28f01afe4e41676e55e18cba9d1
MD5 6f34c858300f3c136cc0b030416d0739
BLAKE2b-256 0c4b7d54f097a5d7a1f7f17aec549449d644eeaab244b711ccde1aec63ee20e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 368f439fcbcbed78407c5bd27b717b3b061f2cfc8dcb9f6661d96605c8464c2a
MD5 6b74f43a19f03f6780696006d34cb2eb
BLAKE2b-256 99b86894f75c8ed938714371dff7ca023c9182cd9ce6461827219633c54d9fcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 534468cc1aa2a8615c53bc97768fdeac6f7b4062d829c55e0a40e25a3c28dc04
MD5 7c81b7103308e9d33441c47c9cbdc6cc
BLAKE2b-256 b8eba8337b0fd5a4e0d0fd01684372af0ae1fa3740818b25d0a407234b391942

See more details on using hashes here.

File details

Details for the file python_dp-1.1.3rc2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 639bb53a6952d593f645c5fc36a27e7ade54d28f531f64493644df630645e57c
MD5 3f8cf7aceda1be71b33b10ab8c10e93e
BLAKE2b-256 26cce36bd97aa4687c85bd7d15710a5b49849321147085befcc346a4530083ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 9646b469cf57cb319822dac520d589039b2ec542036a701430b68a26ecafb6ef
MD5 8fe7464c4e7d076954067c583cf7bf32
BLAKE2b-256 053a4a727fef5bc1a7779b3434f003731d538ded367d4a9f8aa61251c7e39aef

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