Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Examples

End-to-end recipes for the Data Quality V2 API: pipeline gates, monitors as code, case syncing, and maintenance windows

These recipes combine the Data Quality V2 endpoints into complete workflows. Each one is written in Python with requests and uses the same setup, so you can copy the pieces you need into your own scripts, Airflow tasks, or CI jobs.

Setup

Every recipe reads your API key and base URL from environment variables and shares two helpers: one for requests, and one for paging through search results.

export DECUBE_API_KEY="your-api-key"
export DECUBE_BASE="https://connect.<REGION>.decube.io/api/v1/data/data_quality"
import os, time, requests

BASE = os.environ["DECUBE_BASE"]
HEADERS = {"X-Decube-Api-Key": os.environ["DECUBE_API_KEY"]}

def call(method, path, **kwargs):
    response = requests.request(method, f"{BASE}{path}", headers=HEADERS, **kwargs)
    if response.status_code == 400:
        raise RuntimeError(f"{method} {path} failed: {response.text}")
    response.raise_for_status()
    return response.json() if response.content else None

def search_all(path, body):
    """Page through a search endpoint and return every item."""
    items, page = [], 1
    while True:
        result = call("POST", path, json={**body, "page_size": 100, "page_number": page})
        items += result["items"]
        if len(result["items"]) < 100:
            return items
        page += 1

Gate a pipeline on a data quality check

Run a check as soon as your pipeline loads a table, and stop the pipeline if the check fails. This keeps bad data from reaching the models and dashboards downstream.

The monitor must use a manual schedule — see Trigger a run for the requirements.

To use this in Airflow, call run_check from a PythonOperator placed after the load task. The task fails when the check fails, and the downstream tasks don't run. In dbt or any other CI step, run the script after the build and let the non-zero exit code stop the job.

Create monitors as code

Keep monitor definitions in a file under version control, and apply them with a script that creates only the monitors that don't exist yet. The script matches on monitor name, so run it as often as you like.

The UI asks you to run Test Value before saving a Custom SQL monitor. Run your sql_query on the source yourself first to confirm it returns the failing rows you expect.

To apply changes to monitors that already exist, read each one with Get a monitor, compare it with your definition, and send the difference through the update endpoints. Keep in mind that most configuration changes create a new version.

Sync new cases to your ticketing tool

Pull the cases that received incidents since your last sync, open a ticket for each one that doesn't have an owner yet, and assign the case so your team sees who's on it in Decube as well.

The incident's evidence and debug_query give the ticket enough context to start the investigation without opening Decube. When the ticket is resolved, close the case with {"action": {"value": {"type": "close"}}}.

Pause monitors during maintenance

Disable every active monitor on a table before a backfill or migration, then turn the same monitors back on afterwards. Disabling stops scheduled runs, so the maintenance doesn't raise incidents.

Store the returned IDs so that you re-enable only the monitors you paused, and leave monitors that were already disabled as they were.

Report on monitor health by team

Use custom attributes to tag monitors by owning team, then pull a summary of which monitors are failing for each team. The same pattern works for any attribute you use, such as domain or regulatory classification.

Add a custom_attributes filter to the search body to narrow the report to one team.

Last updated