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.2rc3-cp39-cp39-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9

python_dp-1.1.2rc3-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.2rc3-cp38-cp38-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_dp-1.1.2rc3-cp38-cp38-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8

python_dp-1.1.2rc3-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.2rc3-cp37-cp37m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.7m Windows x86-64

python_dp-1.1.2rc3-cp37-cp37m-manylinux1_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.7m

python_dp-1.1.2rc3-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.2rc3-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c10b36f53c397677dd91856d18010177c2121ad0de62564d26b85cea81a3d814
MD5 b9e0312c3dcc740cc88ed57e92c1e198
BLAKE2b-256 4503a58ae7c650f8ed7d49f512670cfabf010e874cceee2692f848b5088da596

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 817f5e23365fd6a002144f4fad463ebf2574a28e75907d25c60aa4fbd701d817
MD5 8a4374a81c99619c47ac937054b2975a
BLAKE2b-256 a24da1014a8ee60a27c8e4e05b9f2484d04756841c413b7730886145dc765ccb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 032499fb3fa1ef9e8957685e3cb6b046165b5f61155a347f8eb51399fdf3eac6
MD5 db8d177978f28ecd6da3ac5ac3f826eb
BLAKE2b-256 a59f6403219e72bcbad6d02078f40725998ea480c16df34ce0f301dee8d3826b

See more details on using hashes here.

File details

Details for the file python_dp-1.1.2rc3-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ef92615d648eac9ac996c71b0063e0fef7b52a718eb0cc58a466a6868d5048ec
MD5 53601898ea25c34927ab035ad06dc9ae
BLAKE2b-256 54ed8b63961bcdf65bbd23d6ceec4650af021fcdb8f23f52bc33113f95adaa52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 edc4344fac5ee6faf38b809b888592ba52142fe2fccf71127bcdfd6a3815c2a7
MD5 2b662126ba0b8c26bf004bbfab385576
BLAKE2b-256 d50d9a87c9cf36ce4ebf062b4f39c625f0bd6515b70ba7fa79ac74c8dd05fc27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 08654b5221a31879b1c3a1c877990be5638474515e39b04c1388b5465814d616
MD5 1ee2596d7d2ef7a974dc9db3224fa64f
BLAKE2b-256 f222dd7ca9e4e78cd6735cb6c6eb49578e492e5574356a79e0d171def944d36c

See more details on using hashes here.

File details

Details for the file python_dp-1.1.2rc3-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 7b33089f9decad822452241fc17ef5448f2b1ed2c157ba80cd49c787b8048e40
MD5 de34c969bd238b70d3a0a11f5fd8e6a2
BLAKE2b-256 fdc3c16e5f31df82a11e38cb864d961fb745fc6910de3da1f1484a478e77edb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b37a38d0896042eec8a19237768d8b09ab00833814f1935c45b34bfbfaa1af64
MD5 6f1eebb03f9f1a77a0bd1c3b932e1d72
BLAKE2b-256 84f528f9052473333c84a80c3ff9232b21815c18eaed3e72ef47662eb28b06b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.2rc3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a575be444ad28a241c787b63f8f1d176ab0a074f4049fd7bd9b422ad7a5aa2c7
MD5 08c1fc4e463226f660a0657601bde670
BLAKE2b-256 e6fc6516ea884e0590b4d4e525fb6dcc72992c2aa0d0f1dd6dff4eab318795ca

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