Skip to main content

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.

Metadata

Release files for aircloak-tools 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aircloak-tools 0.2.2
File Size Uploaded
aircloak-tools-0.2.2.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aircloak-tools 0.2.2
File Interpreter ABI Platform
aircloak_tools-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / aircloak-tools-0.2.2.tar.gz

Download URL aircloak-tools-0.2.2.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d2857d301f255cf889897ea70eb5fa28f4d73d656e46dccb95fff9b0b73ba0ad
BLAKE2b-256 checksum
How to use checksums
fb35876c06f031db317c08c4051c510ad11500573ed78d2e05e5b772eaee4489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.6 Linux/5.4.39-linuxkit

Release files / aircloak_tools-0.2.2-py3-none-any.whl

Download URL aircloak_tools-0.2.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15c6a6cbd8e95b0aedd1ea5b675a86a90c290299861611a78521c01c798e0b97
BLAKE2b-256 checksum
How to use checksums
85e7e3ab181cc9b7872bca68a481c0c976f835ab66d318c189e5199819774516
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.6 Linux/5.4.39-linuxkit

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page