Skip to main content

Tools for querying an Aircloak service.

Project description

GitHub license GitHub issues

Python Aircloak Tools

Tools for querying an Aircloak api.

This package contains two main components:

  • Aircloak Api: Wrapper around psycopg to query Aircloak directly.
  • Explorer: An interface to Diffix Explorer for data analytics.

Aircloak Api

The main aim is to provide an Aircloak-friendly wrapper around psycopg2, and in particular to provide clear error messages when something doesn't go as planned.

Query results are returned as pandas dataframes.


Uses Diffix Explorer to return enhanced statistics. Please see the project homepage for further information about Explorer.


The package can be installed in youir local environment using pip:

pip install aircloak-tools

To use Explorer Features you will also need to run Diffix Explorer.


The following code shows how to initiate a connection and execute a query.

As a pre-requisite you should have a username and password for the postgres interface of an Aircloak installation (ask your admin for these). Assign these values to AIRCLOAK_PG_USER and AIRCLOAK_PG_PASSWORD environment variables.

import aircloak_tools as ac



TEST_DATASET = "cov_clear"

with ac.connect(host=AIRCLOAK_PG_HOST, port=AIRCLOAK_PG_PORT,
                user=AIRCLOAK_PG_USER, password=AIRCLOAK_PG_PASSWORD, dataset=TEST_DATASET) as conn:


    tables = conn.get_tables()


    feeling_now_counts = conn.query('''
    select feeling_now, count(*), count_noise(*)
    from survey
    group by 1
    order by 1 desc

The easiest way to use Diffix Explorer is with the Docker image on docker hub. More detailed information on running Diffix Explorer is available at the project repo. As an example, you can use explorer to generate sample data based on the anonymized dataset as follows:

from aircloak_tools import explorer

EXPLORER_URL = "http://localhost"
DATASET = "gda_banking"
TABLE = "loans"
COLUMNS = ["amount", "duration"]

session = explorer.explorer_session(base_url=EXPLORER_URL, port=EXPLORER_PORT)
result = explorer.explore(session, DATASET, TABLE, COLUMNS)

assert result['status'] == 'Complete'

print(f'{COLUMNS[0] : >10} |{COLUMNS[1] : >10}')
for row in result['sampleData']:
    print(f'{row[0] : >10} |{row[1] : >10}')

# Should print something like:
#    amount |  duration
#     33000 |        12
#     43000 |        36
#     57000 |        12
#     91000 |        24
#     97000 |        48
#    101000 |        60
# etc.

Project details

Download files

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

Files for aircloak-tools, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size aircloak_tools-0.2.2-py3-none-any.whl (6.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aircloak-tools-0.2.2.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page