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.5rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

python_dp-1.1.5rc4-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.5rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

python_dp-1.1.5rc4-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.5rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_dp-1.1.5rc4-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.5rc4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_dp-1.1.5rc4-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.5rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8d40e304a10ed0a726bffe306f5b71961e37d329ecdb8a3ee637d25ab7efc80
MD5 71a284ebb7edf71821259bf096bc4e25
BLAKE2b-256 8f2c8326c370509516ad923b80d940ef912ef9673688242580749d1082de6191

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6f16d459a41212eefd761b705af43d0397871a892178a9bbef765a68cc82cecd
MD5 1997b876718f46627ddc2ddfda675773
BLAKE2b-256 8f2ee75c7185e3023773b68921c9a98318d14ce5f818aa72834bf1824e25b861

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 51c3cb40161417a4f2195c131f64125f82f57f84635f49c717a578f147b1b0ee
MD5 9c7786ef227358f2ed24140c49e6deed
BLAKE2b-256 ad69bf05823c6ed57551c3ba8b1953269eae9e992420a2c930d2c5c17b5bc2a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8e9530f9cf273c9c677be7f7af1327f314926ae937c348868bbfc6a1c2fb4cb1
MD5 8ead671941b77c327049ff56fc991d7e
BLAKE2b-256 c6b9ecf69c0eeb51f4e41029e58766e227e4d7821fe489538a1684917b30900f

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0471c394a18387d36fb5ff3fcaedb899ec0ac73331bc63c591138811cc666c1
MD5 2257fdc2aeddb8ab19abade34598f75c
BLAKE2b-256 b98748acb8c6abc31eb86d05c7ac7b9af3003347007b85428c18405f0ea6291b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e58527418620b27c2a17cb538a8bd890f2ddc7f85fb20c530f0c5134af603c42
MD5 923cf3216d80c3dd225190dd7b944c71
BLAKE2b-256 97bfb339eb9d1371295693902be58c677b69b0d370a78bde4d6413efd2734a04

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c8fc7f0a211c1149adf55caa81612c19a9924bb6bb247eff43588d5a7e662ef
MD5 92acf72f8b64f1b70bc1da6a288a3f66
BLAKE2b-256 88fb2201cf555ed4b94f13e770f04797614d34260510509a1e71e5a2c2e6b2f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.5rc4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 db6910bebbac063a80b1b2eebacf381ff2cd4c042044005daa2c31e34ef27d6e
MD5 ff776e5b69c380e58691a85716bd9984
BLAKE2b-256 28f22ff758d7ed841471b654859c98944a80bc25601d5db3f24a21b76aad8527

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