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.0.3-cp39-cp39-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9

python_dp-1.0.3-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.0.3-cp38-cp38-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8

python_dp-1.0.3-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.0.3-cp37-cp37m-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.7m

python_dp-1.0.3-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.0.3-cp36-cp36m-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.6m

python_dp-1.0.3-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.0.3-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.3-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.9
  • 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.9.5

File hashes

Hashes for python_dp-1.0.3-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0f53d8fc0f3c147317d0b08f960ab8072a7a9341ac031aefe38fdd58f88fc759
MD5 eb0f558096966e295283ebac2f43594b
BLAKE2b-256 08b86d56f1e34dd394fb1ca4b5afb7299611b4404f163cf20292c356aa63dd1a

See more details on using hashes here.

File details

Details for the file python_dp-1.0.3-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.3-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.9, 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.9.5

File hashes

Hashes for python_dp-1.0.3-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 7086931a372309f63e9f35afb74d824909a737c1be1fe58e3bd46d5146ff3822
MD5 011a4f75e9ab038b0b63e1c1bfc8e014
BLAKE2b-256 c55ec6e8c7aa8e9c16adace9ebf7a1b67641528fadb37f0217af95ac02798a75

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_dp-1.0.3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.8
  • 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.0.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e4993e875d839656ae7dffb8fe704570961094b959f48819502899d821837a2b
MD5 451232f45d6d29e529d4e7e78bfa92ea
BLAKE2b-256 280c0b2dff7924957c66b0ba76d545b37422617f4578a392c68fcbf7d7ed0432

See more details on using hashes here.

File details

Details for the file python_dp-1.0.3-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.3-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.10

File hashes

Hashes for python_dp-1.0.3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 36be646206ac04912cfa001a0f4af7307239c218803643e5bdd338852647b64f
MD5 9431c1fb65cac59751a02a2930099de1
BLAKE2b-256 1820b356ab6b52d644915cdca3854342c8c43453b83d3582ec0a5f505b48e949

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_dp-1.0.3-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.7m
  • 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.10

File hashes

Hashes for python_dp-1.0.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5ec5285e8965e7eab15c40d34d2fe24c3d0e1d1d9de67361d7ebd2570092fe7e
MD5 d99fc95e7017992b3cf68ca008fb1b17
BLAKE2b-256 bbdc42dd2accca017dc8d7712324fe523e3fa2502f8deda2cb0272410d737178

See more details on using hashes here.

File details

Details for the file python_dp-1.0.3-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.3-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.10

File hashes

Hashes for python_dp-1.0.3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e4a482fcaa3f511f63022f55665b54762e40680ba34a00914f2d7b38d159ee2e
MD5 ee7485a153bc53b18fb70e573f0566c1
BLAKE2b-256 8ea1273d5f4f78df5fa3d45a557000da6c53139b3796ea525cc97a1ddf219284

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_dp-1.0.3-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.6m
  • 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.13

File hashes

Hashes for python_dp-1.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d100ceec7f5d96d377d55a67fa349ff7822af7650feeb79fe9256d598a601d86
MD5 540f8c98107f0f28eb671e52249abcee
BLAKE2b-256 2f06ee501704d2a2784eab38d8193846a9535dcc7e042f76655870985e2b5e30

See more details on using hashes here.

File details

Details for the file python_dp-1.0.3-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_dp-1.0.3-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.13

File hashes

Hashes for python_dp-1.0.3-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2ef746034640e39e258e74b90bcec77dc2bc2451917c9b274ce5cbf1575d8710
MD5 f22998c1aaeb1b9d435cc99fd37a0b72
BLAKE2b-256 d25af07765cd05a58d1906c2f3d7685967aa555447f99c01803243b76a884b92

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