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

If you're not sure about the file name format, learn more about wheel file names.

python_dp-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5-cp314-cp314-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 15.0+ universal2 (ARM64, x86-64)

python_dp-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5-cp313-cp313-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ universal2 (ARM64, x86-64)

python_dp-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5-cp312-cp312-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ universal2 (ARM64, x86-64)

python_dp-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

python_dp-1.1.5-cp311-cp311-macosx_15_0_universal2.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ universal2 (ARM64, x86-64)

File details

Details for the file python_dp-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 32dde006cffb1e9c3d9469ddc1986d968bc7b87ae404313fd6eb8116751790e7
MD5 fbba058564748b94a16d0a79f2f2beb3
BLAKE2b-256 b08075f5cf75e9fcc62874587adab89c2c454f1f7d1ab9d369957b2cdae59e4a

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp314-cp314-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp314-cp314-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 1a577b535a5ade79aa2273ae37a436ae71437a6ca6c66d81b9cb4059d046c25c
MD5 920c469e01302e7a1e8b7fb94c7fe6cd
BLAKE2b-256 398c778ff3989c33aa6559e2f59563cbe704cb781ca1f1e42741b3e9ed8b187d

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 40cfd8f9a06b1288e6563590c81bfcdfbf3f35437c96fa83595d4e1be04a8a60
MD5 fcce42d22af6280a12abb4db85a2ad27
BLAKE2b-256 840a9eebda38854bb874e23db389af09369f44ce1a4ff0280765a331dbd15856

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp313-cp313-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp313-cp313-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 e57571098bd6f1b18f4c601ea43ae7771f43519509e573fe6e4dc76467cdffde
MD5 5057125369827bda0aaf7e31dce9a670
BLAKE2b-256 968995b0d5fe3f156811b77d88a8bdff1a8d1fe26ec3ba7411a3c23fd8eac80c

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9dd5c8fbac6398c96a90f0644601bd36ccc7f35dbc4d09376f9f4489e7984621
MD5 c871ad93127b9048a30224b9f67a9924
BLAKE2b-256 3db06032a974a9d293ebbb8565a6947a831484a0e076787a8c9a13e6171361dc

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp312-cp312-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp312-cp312-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 cc0fe9e1557eaa761663ccd379818838d88d139983c47ce75ef029ae479d40cb
MD5 1acb815fe3267399ac31b196a14b8713
BLAKE2b-256 7010a15bfbf2026a7432e53aa15d7d6c19890ada91f5b174abbc5651bfbebdad

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0400782a833476537e0caed7c9755cae826145410dea6e8676c8a23cb6968500
MD5 725789fcac2b9849bc1e1d6a144122af
BLAKE2b-256 bc05de47590f7cbd8515d5b9a60ffd7c62059040ba23ff1fa5f878c3f887298e

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5-cp311-cp311-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5-cp311-cp311-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 f5566ba4a6529fb1aa2bb0c0c7eb9cb97c6e0f91fcd327ec5a70f18f6b81414a
MD5 1b83910b3ef32266e690a50751fba978
BLAKE2b-256 e044a7f329156f22a3eea41f40887d492bf3dd399bc7bb209d0db1b6cdd704ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page