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.

Explorer

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

Installation

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.

Example

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

AIRCLOAK_PG_HOST = "covid-db.aircloak.com"
AIRCLOAK_PG_PORT = 9432

AIRCLOAK_PG_USER = environ.get("AIRCLOAK_PG_USER")
AIRCLOAK_PG_PASSWORD = environ.get("AIRCLOAK_PG_PASSWORD")

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:

    assert(conn.is_connected())

    tables = conn.get_tables()

    print(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"
EXPLORER_PORT = 5000
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.

Source Distribution

aircloak-tools-0.2.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

aircloak_tools-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file aircloak-tools-0.2.0.tar.gz.

File metadata

  • Download URL: aircloak-tools-0.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/4.19.76-linuxkit

File hashes

Hashes for aircloak-tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2a0baa66cba607989033e13a20abdd9a23d2cc79ae0e12b1fa79c015405a4dee
MD5 b05d0e9bb0c95066a277336ef9629a4e
BLAKE2b-256 d290703d47202dce5792210648938f3867b21bde9b828ce646e2e0d9a444df49

See more details on using hashes here.

File details

Details for the file aircloak_tools-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aircloak_tools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/4.19.76-linuxkit

File hashes

Hashes for aircloak_tools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9c39323b8627e57fef7e27c05d14cab30a0dc2f0d8d9c6c19f3b731a8fb5f5b
MD5 d03ff6d4f489096f8f42866b4a136253
BLAKE2b-256 9777bd2fcbef791b84ef0b03feb6f0a99e632d7217970d2b68d53dab4649d471

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