dbt-artifacts-parser

0.13.1 · active · verified Thu Apr 16

A Python library for parsing dbt artifacts (like `manifest.json`, `run_results.json`, `catalog.json`) into strongly-typed Pydantic objects. It provides Python representations for various dbt artifact schemas, enabling easy programmatic access and manipulation of dbt project metadata and execution results. The library is actively maintained and frequently updated to support the latest stable dbt artifact versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a dbt artifact JSON (here, a minimal manifest) and parse it into a Pydantic object using `parse_artifact` and the appropriate schema class (e.g., `ManifestV10`). You can then access artifact data via dot notation.

import json
from dbt_artifacts_parser.parser import parse_artifact
from dbt_artifacts_parser.schema.manifest import ManifestV10

# In a real scenario, you'd load your manifest.json file, e.g.:
# with open('path/to/manifest.json', 'r') as f:
#     manifest_dict = json.load(f)

# Example minimal valid manifest structure for demonstration
manifest_json_str = """
{
  "metadata": {
    "dbt_schema_version": "https://schemas.getdbt.com/dbt/manifest/v10.json",
    "dbt_version": "1.7.0",
    "generated_at": "2023-10-27T10:00:00.000000Z",
    "invocation_id": "test_invocation",
    "env": {},
    "adapter_type": "postgres",
    "project_id": "test_project",
    "user_id": "test_user",
    "send_anonymous_usage_stats": false,
    "cdd_id": ""
  },
  "nodes": {},
  "sources": {},
  "macros": {},
  "docs": {},
  "exposures": {},
  "metrics": {},
  "selectors": {},
  "disabled": {},
  "files": {},
  "unit_tests": {},
  "artifacts": {}
}
"""

manifest_dict = json.loads(manifest_json_str)

# Parse the dictionary into a strongly-typed Pydantic object
manifest = parse_artifact(manifest_dict, ManifestV10)

print(f"Parsed dbt Manifest (dbt version: {manifest.metadata.dbt_version})")
print(f"Schema version: {manifest.metadata.dbt_schema_version}")
print(f"Number of nodes: {len(manifest.nodes)}")

view raw JSON →