API Reference
Technical documentation for the Ancestree lineage system. The LineageStore is the public entry point and is accessible directly from the top-level ancestree package — searching, lineage traversal, and visualisation all happen through its methods.
Core Orchestration
The LineageStore is the prime entry point for managing your pipeline.
ancestree.LineageStore
Orchestrates the lineage and interactions of a data pipeline.
The LineageStore manages the physical storage, rule enforcement, and hierarchical relationships between different steps in a data pipeline. The rules need only be specified once as configurations persist. The LineageStore does not need to exist in memory. It can be recreated any time it is required. Provides advanced searching capabilities across the node network.
Source code in src/ancestree/core.py
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 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 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 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 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 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 343 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 400 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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 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 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | |
__init__
Initialises the LineageStore, ensures its directory exists, and loads or creates the ruleset configuration.
On creation the LineageStore saves a .lineage_config.json file. On subsequent re-creation, the store reads from this file. There is no need to resupply rules or gen_triggers at any point after initial creation even if the store no longer exists in memory. The rules and gen_triggers cannot be changed after initial creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Union[Path, str]
|
Root directory for data pipeline. This is where the nodes sit. |
required |
rules
|
Dict
|
A mapping defining the allowed transitions. Defaults to None. |
None
|
gen_triggers
|
List
|
Step types that mark a new generation. When a node of this type is created, its generation number increments by one relative to its parent. Defaults to None. |
None
|
dedupe
|
bool
|
When True, a node that is content-identical to one already in the store is not created a second time: |
True
|
chunk
|
bool
|
When True, artifacts are deduplicated at sub-file granularity. As each node is persisted, its files are split into content-defined chunks stored once in a shared pool ( |
True
|
Examples:
>>> rules = {"clean": ["ingest"], "model": ["clean"]}
>>> store = LineageStore("my_project", rules=rules, gen_triggers=["ingest"])
Source code in src/ancestree/core.py
clear_cache
Discards the store's session read cache (<root>/.cache).
Reading a packed artifact reassembles its bytes into this cache rather
than back into the node directory, so the store never needs compact()
to reclaim what reads would otherwise leak. The cache is pure derived
data — anything in it is regenerated from the chunk pool on the next
read — so clearing it only frees disk, never loses anything. It is also
cleared automatically when the process exits or a with block closes;
call this to reclaim the space sooner.
Source code in src/ancestree/core.py
create_node
Creates a new node while enforcing lineage rules.
The node only materialises on disk once the user writes an artifact or adds metadata; an untouched node is discarded with a warning. If the user's code raises after writing, the partial work is persisted and the node's 'healthy' metadata flag is set to False (True on clean completion).
If the store was opened with dedupe=True and the block completes
cleanly, a node that is content-identical to one already in the store
is not created again: the existing node is reused and the as node
variable is rebound onto it. See LineageStore.__init__ for what counts
as content-identical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_type
|
str
|
The type of pipeline step being performed. |
required |
parent
|
Node | str | list
|
The parent — a Node or node_id, or a list of them for a step that joins several inputs (a merge/join, making the lineage a DAG). Every parent must already exist in this store and individually satisfy the rules; the node's generation is one past its deepest parent. Defaults to None (a root). Examples: |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the step type transition is not permitted according to the store rules. |
Yields:
| Name | Type | Description |
|---|---|---|
Node |
Node
|
The new node, ready to receive artifacts and metadata. |
Examples:
>>> with store.create_node(step_type="clean", parent=ingest_node) as node:
... df.to_csv(node / "cleaned.csv")
... node.add_meta("rows", len(df))
Source code in src/ancestree/core.py
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 234 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 | |
find_in_lineage
Searches a node's ancestry for nodes matching specified search parameters.
This is find_node restricted to a single lineage: only the target node and its ancestors are considered. Values are matched by equality against the searchable metadata; pass a callable to express a predicate instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Union[str, Node]
|
The Node or node_id whose ancestry to search. |
required |
**kwargs
|
Any
|
Key-value pairs to match against the nodes' searchable metadata keys. |
{}
|
Returns:
| Type | Description |
|---|---|
List[Node]
|
List[Node]: The nodes in the lineage that match all provided criteria. |
Examples:
Source code in src/ancestree/core.py
find_node
Search for nodes based on metadata key values. Values are matched by equality against the searchable metadata; pass a callable to express a predicate instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Key-value pairs to match against the node's searchable metadata keys. |
{}
|
Returns:
| Type | Description |
|---|---|
List[Node]
|
List['Node']: A list of node objects that match all provided criteria. |
Examples:
>>> store.find_node(step_type="ingest")
>>> store.find_node(accuracy=lambda a: a is not None and a > 0.8)
Source code in src/ancestree/core.py
flush
Blocks until every queued artifact has been chunked, then reclaims the loose files whose recipe is now durable. This is the only place loose files are removed; it runs on the calling (main) thread, so no reader can be mid-read of a file it removes. Called automatically by the context manager and at interpreter exit; call it directly to converge sooner.
Safe to interrupt: a partial flush just leaves more loose files to reclaim next time, and never loses data.
Source code in src/ancestree/core.py
from_parent
Shortcut to get specific file(s) from the parent node of the specified node.
Equivalent to looking up the node's parent and calling artifacts on it. The typical use is reading the previous step's output as the current step's input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Union[str, Node]
|
The Node or node_id whose parent to search. |
required |
filename
|
str
|
A glob pattern or substring to match against the parent's files, as in |
required |
Returns:
| Type | Description |
|---|---|
List[Path]
|
List[Path]: The matching file paths from the node's parent(s), ready to read directly (as returned by |
Examples:
>>> with store.create_node(step_type="model", parent=clean_node) as node:
... [training_data] = store.from_parent(node, "cleaned.csv")
Source code in src/ancestree/core.py
gc
Deletes chunks in the shared pool that no node references any more.
Scans every node's artifact manifest for the chunks still in use, then removes the rest. A store-level lock makes concurrent collections safe, and chunks written in the last minute are spared so an in-flight pack in another process is never reaped before it records its recipe.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of chunks deleted. |
Source code in src/ancestree/core.py
generate_web_graph
Creates an interactive web graph of node hierarchies and lineage.
Renders every node in the store as a self-contained HTML file — all styles and scripts are inlined, so the file can be opened directly in a browser or shared as-is. Nodes are laid out by lineage and coloured by step type; clicking a node reveals its metadata and artifacts.
The file is written to <store root>/interactive_pipeline.html, and the location is printed on completion.
Source code in src/ancestree/core.py
get_child_nodes
Returns the direct children of the specified node.
Only immediate offspring are returned, not the full subtree. To walk further down the branch, call this on each child in turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Union[str, Node]
|
A Node object or node_id string. |
required |
Returns:
| Type | Description |
|---|---|
List[Node]
|
List[Node]: All nodes whose parent is the specified node. Empty if the node has no children or does not exist. |
Source code in src/ancestree/core.py
get_lineage
Traces the ancestry of the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
str | Node
|
The Node or node_id to trace from. |
required |
Returns:
| Type | Description |
|---|---|
List[Node]
|
List['Node']: A list of Node objects ordered from oldest ancestor to the target node. |
Examples:
>>> history = store.get_lineage("abc12345")
>>> [n.step_type for n in history]
['ingest', 'clean', 'transform']
Source code in src/ancestree/core.py
get_most_recent_node
Finds the single most recently created node that matches the given search parameters.
Recency is determined by the timestamp recorded when each node was created. Useful for picking up a pipeline where it left off, e.g. fetching the latest cleaned dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Key-value pairs to match against the nodes' searchable metadata keys, as in |
{}
|
Returns:
| Type | Description |
|---|---|
Optional[Node]
|
Optional[Node]: The most recent matching node, or None if nothing matches. |
Examples:
Source code in src/ancestree/core.py
get_node
Resolves a node_id string into a Node object, loading it from disk.
Accepts a Node as well (returned unchanged), so it can be used to normalise any "node or id" argument. Returns None rather than raising if the node does not exist or its metadata cannot be read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Union[str, Node, None]
|
A node_id string, an existing Node instance, or None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Node]
|
Optional[Node]: The resolved Node, or None if the input is None, invalid, or not found. |
Examples:
Source code in src/ancestree/core.py
prune
Deletes a node and the descendants it solely supports.
A descendant is removed only when EVERY one of its parents is also being
removed — a node still reachable from a branch you did not prune survives,
with the pruned parent dropped from its parent_id. (For a plain tree
this is just "delete the whole subtree".) Both the directories on disk and
their index entries are removed. Run with the default dry_run=True first
to preview exactly what would be removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Union[str, Node]
|
Either a node_id string or a Node object. |
required |
dry_run
|
bool
|
If True, returns the list of nodes that would be deleted without deleting anything. Must be set to False to actually delete. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
List[Node]
|
List[Node]: Nodes that were (or would be) deleted, deepest first. |
Raises:
| Type | Description |
|---|---|
PermissionError
|
If the target resolves to the store's root directory. |
Examples:
>>> store.prune("abc12345") # preview only
>>> store.prune("abc12345", dry_run=False) # actually delete
Source code in src/ancestree/core.py
rebuild_db_from_disk
Rebuilds the search index by scanning all node directories on disk.
Use this as a recovery step if the index becomes stale or corrupt — for example after a crash mid-write, manual filesystem changes, or a KeyError from get_lineage suggesting a missing index entry.
Note: only nodes with a valid meta.json are re-indexed. Directories without one are silently skipped.
Source code in src/ancestree/core.py
Working with Nodes
You never construct a Node yourself — they are created by LineageStore.create_node and returned by the store's search and lineage methods. You will interact with them to read and attach metadata, locate artifacts, and build paths inside a node's directory.
ancestree.models.Node
Represents a single step in the pipeline: a directory on disk holding the step's artifacts and a meta.json describing it.
Nodes are not constructed directly. They are created by LineageStore.create_node and returned by the store's search and lineage methods (find_node, get_lineage, get_child_nodes, ...). Interact with a node to read and attach metadata, locate its artifacts, and build paths inside its directory with the / operator.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The node's directory on disk. |
node_id |
str
|
The unique 8-character identifier of the node. |
generation |
int
|
The generation number of the node in the pipeline. |
parent_id |
List[str]
|
The node_ids of this node's parent(s) — a list, since a node may join several inputs. Empty for a root node. |
step_type |
str
|
The type of pipeline step this node represents. |
Source code in src/ancestree/models.py
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 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 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 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 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 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 343 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 400 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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 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 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
metadata
property
The node's full metadata as a dictionary.
Each key maps to an entry of the form {'value': ..., 'type': ..., 'group': ..., 'searchable': ...}. This includes both the structural metadata written by the store (node_id, parent_id, generation, step_type, timestamp, provenance) and anything added with add_meta.
Returns a deep copy: mutating the result does not change the node. Use add_meta to modify metadata.
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]]
|
Dict[str, Dict]: A mapping of metadata key to its entry dictionary. |
Examples:
add_meta(key, value, group='General', data_type='auto', searchable=True)
Attaches a piece of metadata to the node.
Metadata is what makes a node discoverable: every searchable entry can be matched by the store's search methods (find_node, find_in_lineage, get_most_recent_node) and is displayed in the interactive web graph. Adding a key that already exists overwrites the previous entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The name of the metadata entry. |
required |
value
|
Any
|
The value to store. Must be JSON-serialisable. |
required |
group
|
str
|
A heading to group related entries under in the web graph display. Defaults to General. |
'General'
|
data_type
|
str
|
How the value is rendered in the web graph. The default 'auto' infers it from the value: pandas DataFrames render as tables, dicts and lists as formatted JSON, Path objects as inline images (image suffixes) or file links, http(s) strings as links, and everything else as plain text. Pass a type explicitly to override the inference: 'image' for a path to an image file inside the node (the value is rewritten relative to the store root), 'link' for a clickable link, 'table' for a pandas DataFrame (stored as columns/rows), 'json' for a dict or list, 'code' for a monospaced snippet (e.g. the SQL or shell command that produced the node), or 'text' for plain text. |
'auto'
|
searchable
|
bool
|
If True the entry is indexed and can be matched by the store's search methods. Set to False for display-only metadata. Defaults to True. |
True
|
Examples:
>>> with store.create_node(step_type="model", parent=clean_node) as node:
... # Plain values — searchable by default
... node.add_meta("accuracy", 0.94, group="Metrics")
... node.add_meta("epochs", 42, group="Metrics")
... node.add_meta("learning_rate", 1e-3, group="Config")
...
... # Dict/list — rendered as formatted JSON in the web graph
... node.add_meta("params", {"optimizer": "adam", "dropout": 0.3}, group="Config")
...
... # Table — pandas DataFrame rendered as a sortable table; not searchable
... node.add_meta("results", df, data_type="table", group="Outputs")
...
... # Image — path rewritten relative to store root, rendered inline
... fig.savefig(node / "confusion.png")
... node.add_meta("confusion_matrix", node / "confusion.png", group="Figures")
...
... # Code — rendered in a monospaced block
... node.add_meta("query", "SELECT * FROM runs WHERE status = 'ok'", data_type="code")
...
... # Display-only — visible in the web graph but excluded from find_node
... node.add_meta("notes", "rerun after fixing label encoding", searchable=False)
...
... # External link — rendered as a clickable URL
... node.add_meta("wandb_run", "https://wandb.ai/my-org/run/abc123", group="Links")
Source code in src/ancestree/models.py
artifacts(contains='*')
Searches this node's directory returning all files excluding internal metadata. Recursively finds all artifacts regardless of storage depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contains
|
str
|
A glob pattern to filter discovered files. A plain substring also works: it is matched anywhere in the filename, case-insensitively. Defaults to "*" (all files). |
'*'
|
Returns:
| Type | Description |
|---|---|
List[Path]
|
List[Path]: The matching file paths, ready to read or pass to a
loader directly (no need to prefix the store root). A loose file
points inside the node's directory; a packed artifact points at a
reassembled copy in the store's read cache. Either way the path
holds readable bytes, mirroring what |
Examples:
>>> node.artifacts("*.csv")
[PosixPath('/data/store/abc12345/sample.csv')]
>>> pd.read_csv(node.artifacts("sample")[0])
Source code in src/ancestree/models.py
__truediv__(relative_loc)
Allows the use of the '/' operator to create paths inside the node's directory, mirroring pathlib. This is the idiomatic way to choose where to write an artifact. Any intermediate directories in the path are created automatically, so the returned path is always ready to write to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relative_loc
|
Union[Path, str]
|
The string or Path object to append to the node's base path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The resolved destination inside the node's directory. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path escapes the node's directory. |
Examples: