Collate dbt Artifacts Parser

0.1.4 · active · verified Fri Apr 17

Collate dbt Artifacts Parser is a Python library that provides a structured way to parse dbt artifacts like `manifest.json` and `run_results.json` into Pydantic models. It leverages `dbt-artifacts-parser` and simplifies access to dbt project metadata. The current version is 0.1.4, and its release cadence is tied to internal dbt-labs development, though it's publicly available.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a dbt `manifest.json` file using `DbtArtifactParser`. It creates a mock manifest file, initializes the parser with the correct artifact type and schema version, and then parses the file into a Pydantic model. Remember to replace the mock content and path with your actual dbt artifact file.

import json
import os
from collate_dbt_artifacts_parser.parsers import DbtArtifactParser

# Mock a simple manifest.json structure (truncated for brevity)
mock_manifest_content = {
    "metadata": {
        "dbt_schema_version": "https://schemas.getdbt.com/dbt/manifest/v8.json",
        "dbt_version": "1.8.0",
        "generated_at": "2024-01-01T00:00:00Z",
        "invocation_id": "mock_invocation",
        "env": {},
        "adapter_type": "postgres"
    },
    "nodes": {},
    "sources": {},
    "macros": {}
}

# Create a dummy file
dummy_file_path = "mock_manifest.json"
with open(dummy_file_path, "w") as f:
    json.dump(mock_manifest_content, f)

try:
    # Initialize parser for 'manifest' artifact of schema version 'v8'
    parser = DbtArtifactParser(artifact_type="manifest", version="v8")
    manifest_model = parser.parse_artifact_file(dummy_file_path)

    print(f"Successfully parsed manifest of type: {type(manifest_model)}")
    print(f"DBT Version from manifest metadata: {manifest_model.metadata.dbt_version}")

except Exception as e:
    print(f"An error occurred during parsing: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists(dummy_file_path):
        os.remove(dummy_file_path)

view raw JSON →