Privacy parameters epsilon and delta are set when instantiating a Privacy object and apply to each computed column for the session. Privacy cost accumulates as queries are executed. You can track the total accumulated cost using the spent property of the connection's odometer.
Key behaviors:
- Accrual: The odometer is advanced immediately before the differentially private result is returned.
- Column Scaling: Privacy cost increases with the number of columns in a query.
- Session vs. Sum: The total session cost accrues at a slower rate than the sum of individual query costs obtained via
get_privacy_cost because the odometer tracks all mechanism invocations for the life of the session. - Sharing Odometers: You can share an
odometer across multiple readers to track a single privacy budget across different workloads.
from snsql import Privacy, from_connection
# Initialize privacy
privacy = Privacy(epsilon=0.1, delta=10e-7)
reader = from_connection(conn, metadata=metadata, privacy=privacy)
print(reader.odometer.spent) # (0.0, 0.0)
# Execute query and see cost increase
result = reader.execute('SELECT COUNT(*) FROM PUMS.PUMS')
print(reader.odometer.spent) # approximately (0.1, 10e-7)