zettelkasten.datasets¶
zettelkasten.datasets ¶
Dataset resolution: the numbers behind a dataset note.
A dataset note keeps its numbers out of the markdown body. The data block
in its frontmatter records where the bytes live and how to read them::
data:
backend: sidecar | dvc | api # optional; inferred when omitted
format: csv | json | parquet # optional; inferred from the path suffix
content_hash: "sha256:..." # stable identity + cache key (optional)
schema: # optional column declaration
- {name: date, dtype: date}
- {name: close, dtype: float}
path: prices.csv # sidecar/dvc: a file in the source folder
fetch: {provider: url, params: {url: "https://..."}} # api: fetch spec
Resolution is deliberately unified. A path covers both a small committed
sidecar file and a large DVC-tracked file — the only difference is whether a
<path>.dvc pointer sits next to it: if the data file itself is absent we run
dvc pull to materialize it, then read. A fetch spec covers a live API
pull whose bytes are cached under <ANGELO_DIR>/zettel/datasets/<hash>.<ext>
(gitignored and re-derivable, exactly like the full-text cache in ingest.py).
This module never mutates a note; it only reads and normalizes. Writing dataset
notes is the caller's job (server.add_note / the dataset MCP tool).
DatasetTable
dataclass
¶
A normalized in-memory table resolved from a dataset note.
Source code in zettelkasten/datasets.py
slice ¶
Return a copy with rows windowed for pagination.
num_rows is preserved as the FULL count so the caller can report the
total independently of the returned page.
Source code in zettelkasten/datasets.py
compute_bytes_hash ¶
dataset_cache_path ¶
Path to the cached bytes for a content hash + format.
register_fetcher ¶
resolve_dataset ¶
resolve_dataset(note: Any, graph_dir: Path, *, force_live: bool = False) -> DatasetTable
Resolve a dataset note to a normalized in-memory table.
note is a :class:zettelkasten.graph.Note (or anything exposing a
data dict). graph_dir is the source-folder path the note lives in
(ZettelGraph.path), used to locate sidecar/DVC files. Never raises for
routine problems — a missing file or unknown provider resolves to an empty
table with a populated warning so callers can surface it in the UI.
force_live bypasses the api fetch cache so the resolved bytes reflect
the CURRENT source (used by the snapshot restamp). Path backends always read
the current file, so the flag is a no-op for them.
Source code in zettelkasten/datasets.py
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 | |
read_dataset_values ¶
read_dataset_values(note: Any, graph_dir: Path, *, offset: int = 0, limit: int | None = 200) -> dict[str, Any]
Resolve a dataset note and return a paginated values payload.
Shape: {columns, rows, num_rows, offset, limit, backend, format,
content_hash, schema, warning}. num_rows is the full row count; rows
is the requested window.