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.4-cp311-cp311-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

python_dp-1.1.4-cp311-cp311-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11

python_dp-1.1.4-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.4-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

python_dp-1.1.4-cp310-cp310-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10

python_dp-1.1.4-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.4-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

python_dp-1.1.4-cp39-cp39-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9

python_dp-1.1.4-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.4-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_dp-1.1.4-cp38-cp38-manylinux1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8

python_dp-1.1.4-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.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 238abc763ffdc94accd792d53f825b58f4a99bf7153e72f3af2153e9282871d2
MD5 d927f076af3448ed22da96a8e3be5f3c
BLAKE2b-256 1a8b7a9feaebbccd590038a5947967ffd1d4b2ad76b2dd2326d13cd37b2c4a83

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp311-cp311-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp311-cp311-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a9ccf3724cbd74460a3d8baf610d9068a3eb6071eeabfeb69653565b0c2cc9cc
MD5 58f13ebf2ca45708881fc81eeea8cd61
BLAKE2b-256 38ba03034770175ef141e1a6f4fca6bd0d89410d0610dfa0ab373009ae4e36f4

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2eba0f70ae8705dc0682e901d4227dc3eaab880f2cd02db6954a394ccdadfedf
MD5 2a14071adca1a9a04bd0f71e04d86547
BLAKE2b-256 1da4b72e153d28fc206c5b057c7205508c5f7832a562514a18de453521f4ebf0

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e97f8581d92d02caaaf9fee4b0a0b5fdaec594544c54aa9dd9d7cbdf9200cc83
MD5 8fceb22907ef4d390306d2b818ed79b8
BLAKE2b-256 eb08ae5a062673ed1ab2b5ee7974cfefa6164d3efae443b9a1c39a02e132020b

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a152c8e7ec0b72f0a6ec4ed6b542ab43899815ea8b2d04f3ed2e0d3678cefa51
MD5 d5b7681d9e4c81c81999ecfd1b869a38
BLAKE2b-256 1534824811b0eaad9a6c9001b8c6d427bb5d922b8a570f208aefecedf2308e3d

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 778a770d166f29ba8ff9fe028a24af7c04f51299227d0ed6dfe02fca209ed484
MD5 fb1fc76f269545d4d696735cb38adacb
BLAKE2b-256 b522619c96a7c6c951898064b4acd19db2c82e5c20ef35a933dde1c41fe58144

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: python_dp-1.1.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for python_dp-1.1.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c3099c37dcfc06a8d2218521495508b020944b4764ca06b80455386a7860a641
MD5 84ad633cc585f7a0d3ee6e7996f7d1a8
BLAKE2b-256 d7b9ec14af08ddfb0e9758fca693357c8e6f924b4a4652c9c8fbb1cf8698e01f

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp39-cp39-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.4-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 33ef3484ea87f404053ab1ef1dc8c3d4de1bfa8a6d1ab31ea0264f965a08ce61
MD5 f5015c3523f90a11a396b8561a0a493d
BLAKE2b-256 dd7ae479f0ec706d3a007a9c0c4bff33709c59e530951717dca6e48f96a70dfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.4-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 80f1e6872015624684cba619cdbf2fda2981d5462c314a87f20b0ff50aa889ed
MD5 2acd3d0c9fcb457d8f9ac6e68f722c8d
BLAKE2b-256 4f04344a848154f1a8a7b638a24fdbb522bad98b18525e5f37678fca6fd26bd6

See more details on using hashes here.

File details

Details for the file python_dp-1.1.4-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: python_dp-1.1.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for python_dp-1.1.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 65a8599c0c3c139e27c5714aeb03732dbde9017465aa34e334a3f403b1b52d77
MD5 d82f34a469a7a8ffa883a9d8a07c5f3a
BLAKE2b-256 b96e741e3b084c950243a2094a0955f8c3b90df8125d1d748f5a04451345703c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3ed50ec62c55674a25f93cb7a69b55631923d5e3d23c1811ff1a70692558f33f
MD5 52e64c51ca7856e401d8478a09f432ce
BLAKE2b-256 458146c0b62740210612cfcbbb3e938f58e7a7464581a8f95c4e4730f9a5bfb4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_dp-1.1.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 80c9a0ad277d8eacbc850b1869d5cb91d14c078fa18584d749078abd415fe2a4
MD5 37984f51f729693cdfdc5aba8d20504a
BLAKE2b-256 dccce5ea4cd643f5fd3983435a7ef50f31db9db57a0bacea1c669221149c875c

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