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

Uploaded CPython 3.10

python_dp-1.1.3rc3-cp39-cp39-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9

python_dp-1.1.3rc3-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.3rc3-cp38-cp38-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8

python_dp-1.1.3rc3-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.3rc3-cp37-cp37m-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.7m

python_dp-1.1.3rc3-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.3rc3-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b368c0c8d17a9f84bd5c3cd7c2a0bae3b8aca10c58acbbf9147480b0be5f4e61
MD5 877c8159763007ec0600562067700608
BLAKE2b-256 41b3bbccd2cdd83e224c420298de3074ee807055a1e9f34ed1f550a2a31a21fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7a7d23e63bf59836889d0e77be2dc8672f2ee45a36d19e9badf1ed0580ba05d2
MD5 a0c520997962e70805ea822f6f1e3d6e
BLAKE2b-256 a67ab4d093ed2fbf8dfeb4262d53445b083cc5ee196c47eba3b64720b0a9c39e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 022e7bd98763d224ff254b864839292f77c45af1608412070ca611a3c21482da
MD5 76467236f766fd2251df65d6ef4f0ac0
BLAKE2b-256 87b0648b8ec139c3173f47acee19e6981f2083421e56aad792dcb549f99d6158

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6d4757a274337ffc55e4e11fa40666fff568ca8febdd2e545594019ccd8773e8
MD5 84a549f7ac258edd53882440bdaa612b
BLAKE2b-256 d55ba6be9c1fd79e74c1f276fcc346f408e171c1cbd0577b180475759d2bb310

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d4eb594797b5209af202d964486df979ae844e2f69c1ef50276e3f53e718a280
MD5 4891a1e5fcbcbb5f0f05f128385eea2d
BLAKE2b-256 5146247e736c5aac06345d00a3f9f54b7993d0087c7864c719c0c229445e4c97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2a3af00f0431b653cfa4e31fd817ba2a090b3ecb08cab0ddd5a6ad77447ec5fc
MD5 6a2c1280b1c2c8779158e6d2b4f7d577
BLAKE2b-256 e2e1ac711f969e68e32ef2080f1c5b834c634cae5dd69bb1eb2f1b85403dfd9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f9e18279d1e262b9f4a285e46335e545a9d5d647dfdeea7c0d563a2cde944fd5
MD5 f5c2e67f9a05fab7f2e7229472a08f25
BLAKE2b-256 e7317507b68afcc257bb296aab5bc2bbced0c98062deebd971b3c924487b35f9

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