DiffPriv

DiffPriv is a package focused on privacy, with differential privacy and encryption schemes.

DiffPriv Logo

Build Status PyPI Version DeepSource codecov License Downloads Downloads Downloads Chat on GitHub Discussions Conda

The truth is more important than ever—let's make sure easy privacy protection is available.

Differential privacy should be simple. Now that data defines our world, we need to look at the cost of privacy. Let's make protecting privacy easy.



What is differential privacy?

Differential privacy allows for data to be preserved while making sure that attackers cannot gain access to an individual's data. Even if you publish summary statistics (like average age of participants, unlabeled addresses of participants, etc.), attackers can gain access to individual data (like age of each participant, labeled addresses of participants, etc.). In order to achieve this, differential privacy slightly changes the actual dataset to make sure that any uncovered data will not give away personal information. See below for how to get started!


Downloading DiffPriv

To download, open up your command prompt and type

    pip install DiffPriv

or from the source repo:

    git clone https://github.com/Quantalabs/DiffPriv
    cd diffpriv
    python setup.py install

Conda Envioronment

You can install it from conda through the command:

conda install -c conda-forge diffpriv
View Source
"""
DiffPriv is a package focused on privacy, with differential privacy and encryption schemes.

.. include:: ../README.md
"""
__docformat__ = "restructuredtext"

# Sanity Check Imports
import warnings
import json
from urllib import request

# Dependecy Imports
import sys
import csv
import webbrowser
import math
import random
import numpy as np

# Local
from . import diff
from . import enc
from . import cli

# Metadata
__version__ = 'v1.0.1'
__version__ = 'v1.0.2'
__stable__ = True
"""If package is stable or not."""
__source__ = 'https://github.com/Quantalabs/DiffPriv'
"""Source Repo"""
__docs__ = 'https://diffpriv.readthedocs.io'
"""Documentation URL"""

def _sanity_check():
    # Import Requirements
    try:
        import numpy as np
    except ImportError: # pragma: no cover
        raise ImportError(' \
            Please make sure you have numpy installed. If you have cloned the package from the source, then use: \
                pip install -r requirements.txt \
        ')
    
    url = f'https://pypi.python.org/pypi/DiffPriv/json'

    if url.lower().startswith('http'):
        releases = json.loads(request.urlopen(url).read()) # skipcq
    else: # pragma: no cover
        raise ValueError from None

    latest_version = releases['info']['version']
    

    try: # pragma: no cover
        if __version__ != 'v'+latest_version:
            raise AssertionError
    except AssertionError:  # pragma: no cover
        # We ignore code coverage for this because there is no way to test this through pytest, but it has been tested manually
        warnings.warn(
            '\u001b[33m \n'
            'You have DiffPriv '+__version__+', however, newer versions are avaliable. Use \n'
            '   pip install --upgrade DiffPriv \n'
            'to upgrade your package. \u001b[0m'    
        )

_sanity_check()

del _sanity_check