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

Uploaded CPython 3.9

python_dp-1.1.3rc4-cp39-cp39-macosx_10_14_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

python_dp-1.1.3rc4-cp38-cp38-manylinux1_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8

python_dp-1.1.3rc4-cp38-cp38-macosx_10_14_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

python_dp-1.1.3rc4-cp37-cp37m-manylinux1_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.7m

python_dp-1.1.3rc4-cp37-cp37m-macosx_10_14_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc4-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5dd2db750d269282eafc5117fa5cef0410b6f0559419eb1727717df3de3bd54c
MD5 f12d4e53e76f07d082a61c505b483cb7
BLAKE2b-256 424374431389d36a150342bbe4d34c7d2b2a808b9662080ddde55bf2fcd015a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc4-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ac58b711e05c08c9da6fd9426d3cfa6f940a7a804a25255e7feea09fd3d8d6b1
MD5 ee1618ccd2f8b1373af6e502d0e12eb4
BLAKE2b-256 1763a05f9e2c9b2e99fdbe1f8a78ac06c02016c7d109abe3a01894612e31124f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b7d87701f7c75fa66d6dc4d5ae439c8f7a141fa09714395b50f69c60ba3d32cc
MD5 f04a14094ca512aa79701665a508d7ed
BLAKE2b-256 cf845470cfc8bfb0c9dfe4c2f507028538402df5435bf5fdd09cd5b63788ec37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 17f2f5f0284bf91c7c5197ce0b5a9e449596f7c68bea7294925324541f970f3d
MD5 adde2dfe1ad3c82fe4612fdbc5726f1e
BLAKE2b-256 b96c08eea1815e1642fc871aef9cad9c600e988fd3133d44a61c16c57cc0dcaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ec77ee0df97935a3cac6c431f341f6a7c12db399bc8dbcd7ad0ff5f3c0a9abe8
MD5 2cda5d79ec9fa86bb6d69fa746bcb1c7
BLAKE2b-256 a2804d86e3827d5ecc8105df0b83a64e1f6cb1057a6e8bdac6550ac722793ffc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.3rc4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2176d796b417b2d990313db04714f80caa2e5da15fbd52be050aed23b52031ef
MD5 b80c2472e759a14b4736a922d64345b6
BLAKE2b-256 5ac311a7ff5c19f08d0105f7329f132329f83285de4c1110b5b726d30fcda73b

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