Skip to main content

Differentially Private SQL Queries

Project description

License: MIT Python

SmartNoise SQL

Differentially private SQL queries. Tested with:

  • PostgreSQL
  • SQL Server
  • Spark
  • Pandas (SQLite)
  • PrestoDB

SmartNoise is intended for scenarios where the analyst is trusted by the data owner. SmartNoise uses the OpenDP library of differential privacy algorithms.

Installation

pip install smartnoise-sql

Querying a Pandas DataFrame

Use the from_df method to create a private reader that can issue queries against a pandas dataframe.

import snsql
from snsql import Privacy
import pandas as pd
privacy = Privacy(epsilon=1.0, delta=0.01)

csv_path = 'PUMS.csv'
meta_path = 'PUMS.yaml'

pums = pd.read_csv(csv_path)
reader = snsql.from_df(pums, privacy=privacy, metadata=meta_path)

result = reader.execute('SELECT sex, AVG(age) AS age FROM PUMS.PUMS GROUP BY sex')

Querying a SQL Database

Use from_connection to wrap an existing database connection.

import snsql
from snsql import Privacy
import psycopg2

privacy = Privacy(epsilon=1.0, delta=0.01)
meta_path = 'PUMS.yaml'

pumsdb = psycopg2.connect(user='postgres', host='localhost', database='PUMS')
reader = snsql.from_connection(pumsdb, privacy=privacy, metadata=meta_path)

result = reader.execute('SELECT sex, AVG(age) AS age FROM PUMS.PUMS GROUP BY sex')

Communication

Releases and Contributing

Please let us know if you encounter a bug by creating an issue.

We appreciate all contributions. Please review the contributors guide. We welcome pull requests with bug-fixes without prior discussion.

If you plan to contribute new features, utility functions or extensions to this system, please first open an issue and discuss the feature with us.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartnoise-sql-0.2.1.tar.gz (100.7 kB view hashes)

Uploaded Source

Built Distribution

smartnoise_sql-0.2.1-py3-none-any.whl (118.0 kB view hashes)

Uploaded Python 3

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