Parser for dbt manifest.json files using dbt-artifacts-parser. Uses dbt-artifacts-parser for typed parsing of manifest versions v1-v12 (dbt versions 0.19 through 1.11+). Example:: parser = DbtManifestParser("target/manifest.json") parser.parse() models = p
| 46 | |
| 47 | |
| 48 | class DbtManifestParser: |
| 49 | """ |
| 50 | Parser for dbt manifest.json files using dbt-artifacts-parser. |
| 51 | |
| 52 | Uses dbt-artifacts-parser for typed parsing of manifest versions v1-v12 |
| 53 | (dbt versions 0.19 through 1.11+). |
| 54 | |
| 55 | Example:: |
| 56 | |
| 57 | parser = DbtManifestParser("target/manifest.json") |
| 58 | parser.parse() |
| 59 | models = parser.get_models(tag_filter="feast") |
| 60 | for model in models: |
| 61 | print(f"Model: {model.name}, Columns: {len(model.columns)}") |
| 62 | |
| 63 | Args: |
| 64 | manifest_path: Path to manifest.json file (typically target/manifest.json) |
| 65 | |
| 66 | Raises: |
| 67 | FileNotFoundError: If manifest.json doesn't exist |
| 68 | ValueError: If manifest.json is invalid JSON |
| 69 | """ |
| 70 | |
| 71 | def __init__(self, manifest_path: str): |
| 72 | """ |
| 73 | Initialize parser. |
| 74 | |
| 75 | Args: |
| 76 | manifest_path: Path to manifest.json file |
| 77 | """ |
| 78 | self.manifest_path = Path(manifest_path) |
| 79 | self._raw_manifest: Optional[Dict[str, Any]] = None |
| 80 | self._parsed_manifest: Optional[Any] = None |
| 81 | |
| 82 | def parse(self) -> None: |
| 83 | """ |
| 84 | Load and parse the manifest.json file using dbt-artifacts-parser. |
| 85 | |
| 86 | Raises: |
| 87 | FileNotFoundError: If manifest.json doesn't exist |
| 88 | ValueError: If manifest.json is invalid JSON |
| 89 | ImportError: If dbt-artifacts-parser is not installed |
| 90 | """ |
| 91 | if not self.manifest_path.exists(): |
| 92 | raise FileNotFoundError( |
| 93 | f"dbt manifest not found at {self.manifest_path}.\n" |
| 94 | f"Run 'dbt compile' or 'dbt run' first.\n" |
| 95 | f"Expected path: <dbt_project>/target/manifest.json" |
| 96 | ) |
| 97 | |
| 98 | try: |
| 99 | with open(self.manifest_path, "r") as f: |
| 100 | self._raw_manifest = json.load(f) |
| 101 | except json.JSONDecodeError as e: |
| 102 | raise ValueError( |
| 103 | f"Invalid JSON in manifest: {e}\nTry: dbt clean && dbt compile" |
| 104 | ) |
| 105 |
no outgoing calls