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.4rc1-cp311-cp311-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

python_dp-1.1.4rc1-cp311-cp311-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11

python_dp-1.1.4rc1-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.4rc1-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

python_dp-1.1.4rc1-cp310-cp310-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10

python_dp-1.1.4rc1-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.4rc1-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

python_dp-1.1.4rc1-cp39-cp39-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9

python_dp-1.1.4rc1-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.4rc1-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_dp-1.1.4rc1-cp38-cp38-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8

python_dp-1.1.4rc1-cp38-cp38-macosx_10_14_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

File details

Details for the file python_dp-1.1.4rc1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d45ad0f5549c83749ca8aac9f9642b3a63e66cbcdd9831c228a93bbc7fba6e4c
MD5 fcc5260332d8a8d0aefd775547a64d1d
BLAKE2b-256 1bdee8fe91ac45376fb0ce7d9d8bb94a2e5fd87bc810f8c41832a6984e5a4ca4

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp311-cp311-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp311-cp311-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5b876f699c2d57ed65af669c9c2f039f67851a60b805f8192ad9bca44255c887
MD5 6a9e49a656777036837c6828e656a042
BLAKE2b-256 ab039e3272dd7d00b28a1cf6f8afadd804b07769710ce857cd2f276cde4c4fc5

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 eb777d257b5fbe43bad9dd48e37bf996884088e314185de788792d4f319b6ee1
MD5 078f18659f7c570c270dcf7a36ad0179
BLAKE2b-256 8702be8aeda2a917072155ac51e1c428737262e707b10ceea11060f72f257d77

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3f7261f47557ec54b9678a6eaa19d12bf69235667790af07396609049a7f8553
MD5 f78ecaa2b37ab6e0fed8e4951e99fe44
BLAKE2b-256 75ca6a256d5caf0fa61cc4046a47acc3196e155a9e566a22503e0c166b31ed1f

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f33d137161ae96c4719c19c52b63667f200b4c07ec321760c5539bf56990796b
MD5 672bf5fccbb5c123da262e33965b904e
BLAKE2b-256 66a9d15213f16b7be44b002f86f2538712843d5789b06767b590609589e0eefd

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 47aeec37b0009b8b469fa7728ff003ce37d7e0640a150bce0779c64670b26ea1
MD5 51a7e006264ad535d43d4d49458023da
BLAKE2b-256 1dd03e46374bf18674e47893a5f33631594d350fa0fafd1c73bb93371335fff4

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f801d2dcf77fb808d61915a5b5316d6f77b7e0af8c181af9070c9cac8aca9708
MD5 c4b467b81fd5aa48c2f7e8af20be7cbe
BLAKE2b-256 ed28b1d94c3541b061c8f5861fe77fcf8e87d170fb745dc53cddba1da1accbad

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp39-cp39-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fe3443aadb9cb488846be2c486538b08c18e61e0e22ee8cceb10a8865f06c3d5
MD5 1d780669299950c8dedbfff0985f4e91
BLAKE2b-256 3439fbda3787d8301939df2094b679a704dc0ff0bc019020eb5d72213e3aeebe

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3bee606d1f111150fc22375ccb5b814bf58a2d738c1644eba100203b84623275
MD5 ed2b0e05ac6520662d7ca9d92ab43a11
BLAKE2b-256 2ce342bebb643e6e54e8dc2b53b80acc33775e0cc0a1f9f6a3fe25300c22b311

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 66a7d0aa4107ca4d3186d8fab28574cfa679d8a2e669d5f6de335801c64739ec
MD5 5b2fda5dfa51160fce39a6a31bbfca42
BLAKE2b-256 5c17741d33462ba5d2e05012511cddbb9d09ee0e35a8799fa7d623139aa88f20

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 74835236497ab21ccfb370141287a57b67d6f6bff7cf5aedfbcd3a571d8f7cdf
MD5 e0d0924d175ec7eeb6ebd82d5cfa589f
BLAKE2b-256 d70536db395e14148ea51004eab3b7d0996f2e41bb728ee000a9b7a9e2c3109f

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4rc1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4rc1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3a63d10015da638cc0b290060b3b26c44b45328c0e340d207d845b0d909e5565
MD5 c9a6d5e7c960a673d2d11bf986f3af6e
BLAKE2b-256 aad64de1ab968717f639d4400e70aeed51c5193f722dcfa89492322877d4ca84

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