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

Uploaded CPython 3.11 Windows x86-64

python_dp-1.1.5rc1-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.5rc1-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

python_dp-1.1.5rc1-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.5rc1-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

python_dp-1.1.5rc1-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.5rc1-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_dp-1.1.5rc1-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.5rc1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 553b6d4dcf6055d349e6b02b59b6f61b5d86118fefe72decb17cf599db3ac1c8
MD5 3cf0b3f5ee44996518f6b6762dcbba52
BLAKE2b-256 92f0d960886f9ca9e9e60c6949d3e5d4ffe0aee75c1765a3260003bc5426cedd

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 04cf16e4a663292b5201b025dffb2c29db302304ede056454862a91b2c350cd7
MD5 19d3237f519380fc6d5dc5e92d134b98
BLAKE2b-256 b68414c94ae9b0b4a461f0578b446405d450c3cd04a24cc764a60cfc88aaad21

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9d22e7cd7310572ca967e8926929d79fd50268da6487f70f6ac896d0977f08fa
MD5 03470674e41de53c14eeccd2bb8437df
BLAKE2b-256 b333dd27f80c0696bb02c9521ea795bd887d7d6b7e143b8ba30934d1e36c6b7c

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b451c9e3c148957d80c5c515d1c4b3750b02e5b61adf787ddde0844e1d877dfb
MD5 4c22229334b6b2b2a6517c0e65b88c86
BLAKE2b-256 35f25e12587af0a46b0e38b747dd013123fd10991a04077b3049b8d00480bb0b

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c82527db51761b1553b5982d1b86a5085ad9383e367d102f694882d1974e389f
MD5 fc30494486d9c5ecee8252bb68f6dde4
BLAKE2b-256 904fa91376876b3c7eb15c6531b2ed15601de4eceec9048ee735a09754d7eaa5

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 bf240e092f383ed7f19ebd3eafcd91ae27f3472413b9409da0d9b8f1791ee612
MD5 1203a6f1e2e80bbb25f69ca0706ffcab
BLAKE2b-256 4481f33ed79220ed0775243b3e3809f8f2235c73531bcb458ea711bf86a292c4

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 36b5af3add91954f8f19519afe95c059ed7e7a93955fc82549d9a61591a6e589
MD5 01c75c9c5422718818c9b12fe1464c53
BLAKE2b-256 46ece97420c2f75ea2f39c7ca4c017b8df787e8079aef687ed4ac0ba2556f507

See more details on using hashes here.

File details

Details for the file python_dp-1.1.5rc1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_dp-1.1.5rc1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ae8d03458c156159f97712fc4f79dbd6b277bb647c8c3f3a6131e0e9ad14d22e
MD5 2ad1dcd4f902ee737d81ab1a8dca5cb0
BLAKE2b-256 154a06d4783a9cff1ccb1749c311c97d27ad5a5ecc4d9b18cc2a1cb33a4533a5

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