graphs
graphs ¶
Graph export converters for lineage data.
Provides converters to transform LineageGraph into various export formats (Mermaid, Neo4j).
Usage
from crew_dcs.integrations.graphs import MermaidConverter
diagram = MermaidConverter.from_lineage_links(links).export(direction="LR")
GraphConverter ¶
Bases: ABC
Abstract base converter for lineage graph export.
Converters transform LineageGraph (format-agnostic data model) into specific export formats (Mermaid, Neo4j, GraphML, etc.).
All conversion is synchronous - operates on pre-loaded graph data.
convert
abstractmethod
¶
convert(graph: LineageGraph, **options) -> Any
Convert graph to target format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph
|
LineageGraph with pre-loaded nodes and edges |
required |
**options
|
Format-specific conversion options |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Format-specific output (MermaidDiagram, Cypher queries, etc.) |
Source code in src/crew_dcs/integrations/graphs/converter.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
export_to_file
abstractmethod
¶
export_to_file(
output: Any, file_path: str, **options
) -> None
Export converted output to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Any
|
Result from convert() method |
required |
file_path
|
str
|
Destination file path |
required |
**options
|
Format-specific export options |
{}
|
Source code in src/crew_dcs/integrations/graphs/converter.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
LineageEdge
dataclass
¶
LineageEdge(
dependent_node: LineageNode,
dependency_node: LineageNode,
metadata: dict[str, Any] = dict(),
)
Represents a directed relationship between two nodes in the lineage graph.
Edges are derived from dependencies and dependents on LineageNodes. The edge direction is: dependent_node depends on dependency_node.
LineageGraph
dataclass
¶
LineageGraph(
nodes: set[LineageNode] = set(),
edges: set[LineageEdge] = set(),
metadata: dict[str, Any] = dict(),
)
Format-agnostic lineage graph data structure.
Manages nodes and edges representing lineage relationships. Graph construction is synchronous - operates on pre-loaded DomoLineage_Link objects.
All complex traversal logic should be handled by
add_edge ¶
add_edge(edge: LineageEdge) -> None
Add edge to graph (automatically deduplicates by hash/eq).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
LineageEdge
|
LineageEdge to add |
required |
Source code in src/crew_dcs/integrations/graphs/graph.py
136 137 138 139 140 141 142 | |
add_node ¶
add_node(node: LineageNode) -> None
Add node to graph (automatically deduplicates by hash/eq).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
LineageNode
|
LineageNode to add |
required |
Source code in src/crew_dcs/integrations/graphs/graph.py
128 129 130 131 132 133 134 | |
from_lineage_links
classmethod
¶
from_lineage_links(
links: list[DomoLineage_Link],
) -> LineageGraph
Build graph from LineageLink list (synchronous operation).
Constructs nodes and edges from pre-loaded lineage links.
All complex traversal logic should be handled by
This method only: 1. Creates LineageNode objects from links 2. Creates LineageEdge objects from dependencies/dependents 3. Deduplicates nodes and edges (via set operations)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
links
|
list[DomoLineage_Link]
|
List of LineageLink with loaded entities and populated dependencies/dependents |
required |
Returns:
| Type | Description |
|---|---|
LineageGraph
|
LineageGraph with deduplicated nodes and edges |
Source code in src/crew_dcs/integrations/graphs/graph.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
LineageNode
dataclass
¶
LineageNode(id: str, lineage_link: DomoLineage_Link)
Core node representation for lineage graph operations.
Separates data model (LineageNode) from presentation (MermaidNode). Designed for graph traversal, deduplication, and relationship tracking.
All graph construction is synchronous - nodes are created from pre-loaded LineageLink objects, no API calls occur during node creation.
node_key
property
¶
node_key: tuple[str, str]
Unique key for graph operations: (id, entity_type).
Always converts ID to string for consistent key comparison.
from_lineage_link
classmethod
¶
from_lineage_link(link: DomoLineage_Link) -> LineageNode
Create node from lineage link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
DomoLineage_Link
|
LineageLink (may or may not have loaded entity) |
required |
Returns:
| Type | Description |
|---|---|
LineageNode
|
LineageNode with available metadata |
Source code in src/crew_dcs/integrations/graphs/graph.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
MermaidConverter ¶
MermaidConverter(graph: LineageGraph | None = None)
Bases: GraphConverter
Convert lineage graph to Mermaid diagram.
Initialize MermaidConverter with optional LineageGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph | None
|
Optional LineageGraph to convert |
None
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
20 21 22 23 24 25 26 | |
convert ¶
convert(
graph: LineageGraph | None = None,
direction: str = "TD",
include_entity_ids: bool = True,
title: str | None = None,
trace_direction: Literal[
"trace_dependencies", "trace_dependents"
] = "trace_dependencies",
**options
) -> MermaidDiagram
Convert LineageGraph to MermaidDiagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph | None
|
LineageGraph to convert. If None, uses self.graph |
None
|
direction
|
str
|
Mermaid flow direction (default: "TD") |
'TD'
|
include_entity_ids
|
bool
|
Whether to include entity IDs |
True
|
title
|
str | None
|
Title for the diagram |
None
|
trace_direction
|
Literal['trace_dependencies', 'trace_dependents']
|
Direction to trace dependencies |
'trace_dependencies'
|
**options
|
Additional options |
{}
|
Returns:
| Type | Description |
|---|---|
MermaidDiagram
|
MermaidDiagram representation of the graph |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
export ¶
export(**options) -> MermaidDiagram
Convert the stored lineage graph to a MermaidDiagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**options
|
Options to pass to convert() |
{}
|
Returns:
| Type | Description |
|---|---|
MermaidDiagram
|
MermaidDiagram representation of the graph |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
123 124 125 126 127 128 129 130 131 132 | |
export_to_file ¶
export_to_file(
file_path: str,
output: MermaidDiagram | None = None,
footer_text: str | None = None,
**options
) -> None
Export Mermaid diagram to markdown file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to output markdown file |
required |
output
|
MermaidDiagram | None
|
MermaidDiagram to export. If None, converts self.graph |
None
|
footer_text
|
str | None
|
Optional footer text for the markdown |
None
|
**options
|
Additional options to pass to convert() |
{}
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
from_lineage_graph
classmethod
¶
from_lineage_graph(graph: LineageGraph) -> MermaidConverter
Create a MermaidConverter from an existing LineageGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph
|
Existing LineageGraph |
required |
Returns:
| Type | Description |
|---|---|
MermaidConverter
|
MermaidConverter wrapping the graph |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
44 45 46 47 48 49 50 51 52 53 54 | |
from_lineage_links
classmethod
¶
from_lineage_links(
links: list[DomoLineage_Link],
) -> MermaidConverter
Create a MermaidConverter from lineage links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
links
|
list[DomoLineage_Link]
|
List of DomoLineage_Link objects |
required |
Returns:
| Type | Description |
|---|---|
MermaidConverter
|
MermaidConverter with graph created from links |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_converter.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
MermaidDiagram
dataclass
¶
MermaidDiagram(
nodes: list[MermaidNode] = list(),
relationships: list[MermaidRelationship] = list(),
direction: str = "TD",
title: str | None = None,
entity_id: str | None = None,
entity_type: str | None = None,
use_aliases: bool = True,
)
Complete Mermaid diagram with nodes and relationships.
add_entity_dependency ¶
add_entity_dependency(
from_entity: Any,
to_entity: Any,
*,
relationship_type: str = "dependency"
) -> None
Add a relationship between two Domo entities.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
add_federation_node ¶
add_federation_node(
entity: Any,
*,
custom_type: str | None = None,
show_entity_id: bool = False,
show_federation_id: str | None = None
) -> MermaidNode
Add a node with federation-aware type label.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
add_lineage_items ¶
add_lineage_items(
lineage_items: Iterable[Any] | None,
*,
recursive: bool = False
) -> None
Add a collection of lineage items, optionally following dependencies.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
add_lineage_link ¶
add_lineage_link(lineage_link: Any) -> None
Add a lineage link's node and relationships to the diagram.
Handles both fully-hydrated links (with entity objects) and placeholder links (ID + type only, entity=None). Relationship types are derived from entity types via resolve_relationship (e.g., DATA_SOURCE→DATAFLOW becomes CREATED_BY, PAGE→CARD becomes CONTAINS).
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
add_node ¶
add_node(node: MermaidNode) -> None
Add a node to the diagram if it doesn't already exist.
If a node with the same id+type already exists, the new node's data is merged into the existing one — specifically, a hydrated name replaces a placeholder UUID name, and an explicit shape replaces None.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
add_relationship ¶
add_relationship(relationship: MermaidRelationship) -> None
Add a relationship to the diagram if it doesn't already exist.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
76 77 78 79 | |
combine
classmethod
¶
combine(
diagrams: list[MermaidDiagram],
*,
bridge_start_id: str,
bridge_end_id: str,
bridge_type: str = "published",
direction: str | None = None,
use_aliases: bool | None = None
) -> MermaidDiagram
Merge multiple diagrams and add a bridge edge between two nodes.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
export_to_markdown ¶
export_to_markdown(
export_file: str | None = None,
footer_text: str | None = None,
*,
show_instance: bool = False,
show_entity_id: bool = False
) -> str
Render the diagram as a Markdown document with optional file export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
export_file
|
str | None
|
Path to write the markdown file |
None
|
footer_text
|
str | None
|
Optional footer text |
None
|
show_instance
|
bool
|
If True, include domo_instance on node line 3 |
False
|
show_entity_id
|
bool
|
If True, include entity ID on node line 4 |
False
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
find_node ¶
find_node(
node_id: str, node_type: str
) -> MermaidNode | None
Find a node by ID and type.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
29 30 31 32 33 | |
from_entity
classmethod
¶
from_entity(
entity: Any,
direction: str = "TD",
use_aliases: bool = True,
) -> MermaidDiagram
Create a Mermaid diagram shell for a Domo entity.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
from_lineage
classmethod
¶
from_lineage(
entity: Any,
lineage: list[Any],
direction: str = "TD",
use_aliases: bool = True,
) -> MermaidDiagram
Create a fully populated MermaidDiagram from an entity and its lineage.
Combines from_entity + add_lineage_items into a single call. Relationship types are derived from entity types via resolve_relationship.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
The root Domo entity |
required |
lineage
|
list[Any]
|
Pre-fetched lineage items (from entity.Lineage.get()) |
required |
direction
|
str
|
Mermaid flow direction |
'TD'
|
use_aliases
|
bool
|
Whether to use short aliases for node IDs |
True
|
Returns:
| Type | Description |
|---|---|
MermaidDiagram
|
MermaidDiagram with all nodes and relationships populated |
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
print_lineage_summary ¶
print_lineage_summary(lineage: list[Any]) -> None
Print a formatted summary of lineage data.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
to_string ¶
to_string(
*,
show_instance: bool = False,
show_entity_id: bool = False
) -> str
Render the complete Mermaid diagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_instance
|
bool
|
If True, include domo_instance on node line 3 |
False
|
show_entity_id
|
bool
|
If True, include entity ID on node line 4 |
False
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_diagram.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
MermaidNode
dataclass
¶
MermaidNode(
id: str,
name: str,
type: str,
subtitle: str | None = None,
domo_instance: str | None = None,
alias: str | None = None,
css_class: str | None = None,
shape: str | None = None,
url: str | None = None,
)
Represents a node in a Mermaid diagram.
Structured label (rendered at to_string time): Line 1: name (entity title) Line 2: subtitle (chart_type, data_provider_type, or class name) Line 3: domo_instance (if show_instance=True) Line 4: id (if show_entity_id=True)
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the node |
name |
str
|
Display name for the entity (title only — no metadata baked in) |
type |
str
|
Entity type (e.g., PAGE, CARD, DATA_SOURCE) |
subtitle |
str | None
|
Second line — chart_type, data_provider_type, or class name |
domo_instance |
str | None
|
Domo instance name (for federated/multi-instance diagrams) |
alias |
str | None
|
Short alias for the node (e.g., "A", "B", "C") - auto-generated |
css_class |
str | None
|
Optional CSS class for styling (e.g., "FederatedDataset") |
shape |
str | None
|
Mermaid shape name (e.g., "cyl", "notch-rect", "fr-rect") |
url |
str | None
|
Optional URL for click directive linking to the entity in Domo |
from_domo_entity
classmethod
¶
from_domo_entity(entity: Any) -> MermaidNode
Create a MermaidNode from a Domo entity (DomoPage, DomoDataset, etc.).
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
from_lineage_link
classmethod
¶
from_lineage_link(lineage_link: Any) -> MermaidNode
Create a MermaidNode from a lineage link item.
Structured label: - Line 1: entity name - Line 2: chart_type / data_provider_type / class name - Line 3: domo_instance (stored but only shown if flag is set)
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
from_lineage_node
classmethod
¶
from_lineage_node(node: LineageNode) -> MermaidNode
Create a MermaidNode from a LineageNode with formatted display.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
to_string ¶
to_string(
use_alias: bool = False,
indentation: int = 4,
*,
show_instance: bool = False,
show_entity_id: bool = False
) -> str
Render the node as a Mermaid node definition.
Uses the v11.3.0+ @{ shape: <name> } syntax when a shape is set,
falling back to the bracket syntax (["name"]) otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_alias
|
bool
|
If True, use the alias instead of full ID |
False
|
indentation
|
int
|
Number of spaces to indent |
4
|
show_instance
|
bool
|
If True, include domo_instance on line 3 |
False
|
show_entity_id
|
bool
|
If True, include entity ID on line 4 |
False
|
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_node.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
MermaidRelationship
dataclass
¶
MermaidRelationship(
from_node: MermaidNode,
to_node: MermaidNode,
type: str = "DEPENDS_ON",
)
Represents a relationship between two nodes in a Mermaid diagram.
to_string ¶
to_string(
use_alias: bool = False, indentation: int = 4
) -> str
Render the relationship as a Mermaid arrow with type label.
All relationships render as A -->|TYPE| B including DEPENDS_ON.
Source code in src/crew_dcs/integrations/graphs/mermaid/mermaid_relationship.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Neo4jConverter ¶
Bases: GraphConverter
Convert lineage graph to Neo4j Cypher queries.
convert ¶
convert(graph: LineageGraph, **options) -> list[str]
Convert LineageGraph to Cypher CREATE queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
LineageGraph
|
LineageGraph with nodes and edges |
required |
**options
|
Additional options (unused) |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of Cypher queries (nodes first, then relationships) |
Source code in src/crew_dcs/integrations/graphs/neo4j_converter.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
export_to_file ¶
export_to_file(
output: list[str], file_path: str, **options
) -> None
Export Cypher queries to .cypher file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
list[str]
|
List of Cypher queries from convert() |
required |
file_path
|
str
|
Destination file path |
required |
**options
|
Additional options (unused) |
{}
|
Source code in src/crew_dcs/integrations/graphs/neo4j_converter.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |