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 and above. Support for Python 3.5 is being 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.0.2-cp38-cp38-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.8

python_dp-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8 macOS 11.0+ x86-64

python_dp-1.0.2-cp37-cp37m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.7m

python_dp-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.7m macOS 11.0+ x86-64

python_dp-1.0.2-cp36-cp36m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.6m

python_dp-1.0.2-cp36-cp36m-macosx_11_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.6m macOS 11.0+ x86-64

python_dp-1.0.2-cp35-cp35m-manylinux1_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.5m

python_dp-1.0.2-cp35-cp35m-macosx_11_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.5m macOS 11.0+ x86-64

File details

Details for the file python_dp-1.0.2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for python_dp-1.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 499da98c13440fa94b5f9b9485d85f361ce1d6f2dba2ac001c921ddb961b3b6a
MD5 87c33dd5e7c6dd4b5df9f4aa0fde5d6d
BLAKE2b-256 7ddebd147b4018dae466d5533072b9e43a72b09f624b1a1c4db7173f3d7d3e30

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.8, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for python_dp-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0ec4b7e9f671e9f9d95995c02f660e5e68d9deeb79fab1ef97621891ceec3510
MD5 ef41c278e974f76fc9673a90203bde92
BLAKE2b-256 b861764d888b561f53e0502fa8847ed760097f1502f4c75c6ccdceeef2147ab3

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

File hashes

Hashes for python_dp-1.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 690a9dabdd6b80f2425de4bd6800f41c59ac60ab5695513044b49f4371111d04
MD5 53e576015370ad5e0f6641a54d454bb7
BLAKE2b-256 cf3b82a7525908607c115511b8e63d32470350358ffed638bc3e18d885278322

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.7m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

File hashes

Hashes for python_dp-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b1a7435fe92cfd2fb28eb6dac32421e728c24388d65732ecadde23681d68d4f2
MD5 25b646da2df333510461cdb1064a47ec
BLAKE2b-256 d9b9494dd0d3d79f3bc41e1aba280f8832610420a0d6b253152bcbed5063381c

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

File hashes

Hashes for python_dp-1.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2e5f980592ca1050a9230916f924700f54769226a6975bd844d3d9b83d9882e0
MD5 b0dfa6523d7548df6c0168793a465a95
BLAKE2b-256 54dcf5e119e8ea34eb7bc27ce7110fd7796b3ea7d963e482c1056469fcbff9c7

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp36-cp36m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp36-cp36m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.6m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

File hashes

Hashes for python_dp-1.0.2-cp36-cp36m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 31b1f8585d478ec0b29ee4f72da9c079406b3966dbe4e8d29540127e0eef97f2
MD5 98f5545c9edb0baeeaf4591d1528c8a8
BLAKE2b-256 582d3fcaad5f179957ee7eaf3fa64076d5dd4bb4a236da55ef4c6a293b22911d

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.5.10

File hashes

Hashes for python_dp-1.0.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5492dffe53c45fbd46e0f65dd8041bebee1570d0698eca256d85af30d185ff49
MD5 3fd6414b3f19e87aa2d39640bfdd4a30
BLAKE2b-256 f37443abc83482f825184f683f7b688ddbc88caf9418218b3bfecda64dabb1d7

See more details on using hashes here.

File details

Details for the file python_dp-1.0.2-cp35-cp35m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.2-cp35-cp35m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.5m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.5.10

File hashes

Hashes for python_dp-1.0.2-cp35-cp35m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7a4bfd2b4b84174f9ee1461caaf4d4e2bfc78da8af393cbfdc90dfe80c425783
MD5 7f9644bce444185393021d5a3a3f2821
BLAKE2b-256 22def08ccdc5156f1969f3d9cc5190b83678093220296be2fe374d7c8a1c9fa0

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