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

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.7m Windows x86-64

python_dp-1.1.2rc0-cp37-cp37m-macosx_10_14_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

python_dp-1.1.2rc0-cp36-cp36m-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.6m Windows x86-64

python_dp-1.1.2rc0-cp36-cp36m-macosx_10_14_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: python_dp-1.1.2rc0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for python_dp-1.1.2rc0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e9ae12104c051365a59b5040b845f53f3a4bb21f3473a17d364d7fe858e1e398
MD5 5673f8f4b703c54a16bdd2a3d204bc65
BLAKE2b-256 1f834be85cd97a0d0c99d82f205cfd05b76b28bb6b22a49e9f053acb8aef304b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_dp-1.1.2rc0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.13

File hashes

Hashes for python_dp-1.1.2rc0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ed0be76ec34ff8bae74f6aae0bcd5ece0eb4dcedbd31f55f46419e6c8a2ae156
MD5 f9a040d8239419c677f71605a08abc0e
BLAKE2b-256 97166cb353e7d55b1ef84c7132c297505fa589a19835c5cb39cd87b0f7eeb383

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_dp-1.1.2rc0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.9

File hashes

Hashes for python_dp-1.1.2rc0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 db21fea60b38ccb23394869a00d6a4000fa309da6994c2349cf9ca4d0d82e998
MD5 0bacef6cf8800b35c60d79e2e11802b8
BLAKE2b-256 d06210fd1bf011aa455fb724027fbf62fd08437e4a96b8eb19ef148ecc6a5209

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_dp-1.1.2rc0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.13

File hashes

Hashes for python_dp-1.1.2rc0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0ad3fba740a251b81c9961bebb7ace7219a8e4cfca8c7739c58d4c5cd6ea6bec
MD5 dc45cfa6e43f884bed61f9e041e70453
BLAKE2b-256 0676b4d001749e14acdec90113c51fc3d938e46aec16df05eceddcd960022360

See more details on using hashes here.

File details

Details for the file python_dp-1.1.2rc0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: python_dp-1.1.2rc0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.8

File hashes

Hashes for python_dp-1.1.2rc0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 46183a78ec51bbbe53872dc63f11c39d0a44668c269aee3a5604a9915f18e417
MD5 ff686407787fd696c5c95abc65577510
BLAKE2b-256 fd066f2c55aa0398713aa0362e8db92baefb3d16882f19a6f5f45fbc7bdd14e5

See more details on using hashes here.

File details

Details for the file python_dp-1.1.2rc0-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_dp-1.1.2rc0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.15

File hashes

Hashes for python_dp-1.1.2rc0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a7b824fa81e896cf8fb57b99df42bf304fcbd190ec950d184a3ba48b5e03e524
MD5 e8fbfe27605f06ea1648fa5f14eb0605
BLAKE2b-256 56831c43ae2bb29a2adb4ba72828f76a163b928de3b4c4a0f04f21cafc70f4b6

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