Skip to content

Commit 9a14079

Browse files
authored
feat(ledger): download a report as a DataBook (#312)
## Summary The API gains a DataBook download format for a published report: the report's holon as a Markdown document a person reads, each value linked to its fact. `download_report_bundle` now takes it. **Waits on the server.** The format is served by the backend change in RoboFinSystems/robosystems#2130, which is in the release after v1.24.3. Against an API without it, `format="databook"` is rejected by the schema; every other format is unaffected. Twin PR in robosystems-typescript-client: `feature/databook-download-format`. ## Changes **Hand-written facade (`robosystems_client/clients/ledger_client.py`)** - `download_report_bundle(format="databook")` (or `"DATABOOK"`) maps to the `DATABOOK` enum value, and a download with no server-suggested filename is named `.databook.md` rather than falling through to `.tavi.json`. The docstring describes the format. This method is synchronous only; there is no async counterpart to cover. **Regenerated** - Against a local API build that adds the format: the checked-in `schema.graphql` and `graphql/generated/enums.py` gain `ReportDownloadFormat.DATABOOK`, and two descriptions change. The OpenAPI regeneration produced no change to `api/` or `models/`. **Tests** - `test_databook_download_takes_the_short_alias`: the enum sent, the format and content type returned, the fallback filename, and the bytes written to disk. ## Compatibility ADDITIVE. One enum value added to the generated tier (`ReportDownloadFormat`), and one more accepted value for an existing facade argument. No signature, model field or default changes. I compared the emitted models: the only generated diff is the added enum member and the two descriptions. A client minor. ## Testing `just test-all`: 758 passed, 17 skipped; format, lint and typecheck clean. Regeneration ran in-session against a local API on the branch that adds the format (`just generate-sdk`, then `just generate-graphql`). Run by hand against that local API: `download_report_bundle(graph_id, report_id, format="databook", to=...)` returned a 37 KB `text/markdown; charset=utf-8` document named `<report>-g2.databook.md`, and the SHA-256 it states for its holon equals the hash of the holon downloaded for the same report through the same facade. Not run: `just build-package` (no packaging change). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents 5500573 + 17dadad commit 9a14079

4 files changed

Lines changed: 44 additions & 10 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@
796796
_DOWNLOAD_FORMAT_ALIASES = {
797797
"holon-jsonld": "HOLON_JSONLD",
798798
"holon-jsonld-lineage": "HOLON_JSONLD_LINEAGE",
799+
"databook": "DATABOOK",
799800
"xbrl-2.1": "XBRL_2_1",
800801
"tavi": "TAVI",
801802
}
@@ -3833,9 +3834,9 @@ def download_report_bundle(
38333834
A download is a read, so the presigned URL is resolved through the
38343835
GraphQL ``reportDownloadUrl`` field (the REST download route was
38353836
retired). Every flavor resolves to a short-lived presigned S3 URL —
3836-
the holon is stamped at publish time; the Tavi model, the XBRL and the
3837-
holon with lineage are materialized + cached on first request. The client follows the URL
3838-
and pulls the bytes.
3837+
the holon is stamped at publish time; the Tavi model, the XBRL, the
3838+
DataBook and the holon with lineage are materialized + cached on first
3839+
request. The client follows the URL and pulls the bytes.
38393840
38403841
Args:
38413842
graph_id: Graph identifier owning the Report.
@@ -3846,9 +3847,12 @@ def download_report_bundle(
38463847
Project Tavi compiled model), ``"xbrl-2.1"``, or
38473848
``"holon-jsonld-lineage"`` (the holon with its ``#lineage`` graph:
38483849
the ledger lines, entries and events behind every frozen figure,
3849-
for this graph's own members). The enum names ``"TAVI"`` /
3850-
``"HOLON_JSONLD"`` / ``"HOLON_JSONLD_LINEAGE"`` / ``"XBRL_2_1"``
3851-
are also accepted.
3850+
for this graph's own members), or ``"databook"`` (the holon as
3851+
a Markdown document a person reads: each value links to its fact
3852+
in the holon, which it names as its source; to the holon what
3853+
inline XBRL is to XBRL). The enum names ``"TAVI"`` /
3854+
``"HOLON_JSONLD"`` / ``"HOLON_JSONLD_LINEAGE"`` / ``"DATABOOK"`` /
3855+
``"XBRL_2_1"`` are also accepted.
38523856
to: Optional file path to write the bytes to. When set, the
38533857
returned ``ReportBundleDownload.path`` points at the
38543858
written file.
@@ -3896,6 +3900,7 @@ def download_report_bundle(
38963900
"XBRL_2_1": "zip",
38973901
"HOLON_JSONLD": "holon.jsonld",
38983902
"HOLON_JSONLD_LINEAGE": "lineage.holon.jsonld",
3903+
"DATABOOK": "databook.md",
38993904
}.get(gql_format, "tavi.json")
39003905
filename = (
39013906
_parse_filename(artifact.headers.get("content-disposition", ""))

‎robosystems_client/graphql/generated/enums.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ class ReportLifecycle(str, Enum):
1010
class ReportDownloadFormat(str, Enum):
1111
HOLON_JSONLD = "HOLON_JSONLD"
1212
HOLON_JSONLD_LINEAGE = "HOLON_JSONLD_LINEAGE"
13+
DATABOOK = "DATABOOK"
1314
XBRL_2_1 = "XBRL_2_1"
1415
TAVI = "TAVI"

‎robosystems_client/graphql/schema.graphql‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,9 @@ type Query {
780780
The only way to download a report's bundle. Every format resolves to a
781781
short-lived presigned S3 URL which the client follows directly — the
782782
field returns the URL, never the bytes. The holon is stamped at
783-
publish time; the Tavi, the XBRL and the holon with lineage are
784-
materialized and cached on first request. `HOLON_JSONLD_LINEAGE` carries
783+
publish time; the Tavi, the XBRL, the DataBook and the holon with lineage
784+
are materialized and cached on first request. `DATABOOK` is the report as
785+
Markdown a person reads, written from the holon and pointing back at it. `HOLON_JSONLD_LINEAGE` carries
785786
the books behind the report's frozen figures, so it is for this graph's
786787
members only: a report shared in from another graph raises
787788
`REPORT_BUNDLE_NOT_AVAILABLE` for it. `expiresIn`
@@ -4580,8 +4581,8 @@ type InformationBlockChartSeries {
45804581
Presigned-URL response for a published Report's serialization bundle.
45814582
45824583
Every flavor resolves to a short-lived presigned URL pointing at the
4583-
bundle in S3 — the holon is stamped at publish time; the Tavi and
4584-
XBRL 2.1 are materialized on first download and cached by
4584+
bundle in S3 — the holon is stamped at publish time; the Tavi, the
4585+
XBRL 2.1 and the DataBook are materialized on first download and cached by
45854586
`generationCount`.
45864587
The client follows `downloadUrl` to fetch the artifact directly
45874588
from S3 (the API never streams the bytes). Mirrors the
@@ -4614,6 +4615,7 @@ type ReportBundleDownload {
46144615
enum ReportDownloadFormat {
46154616
HOLON_JSONLD
46164617
HOLON_JSONLD_LINEAGE
4618+
DATABOOK
46174619
XBRL_2_1
46184620
TAVI
46194621
}

‎tests/test_ledger_client.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,6 +3286,32 @@ def test_lineage_download_takes_the_short_alias(
32863286
assert result.format == "holon-jsonld-lineage"
32873287
assert result.filename == "rpt_01-g3.lineage.holon.jsonld"
32883288

3289+
@patch("robosystems_client.clients.ledger_client.httpx.Client")
3290+
def test_databook_download_takes_the_short_alias(
3291+
self, mock_client_cls, mock_config, graph_id, tmp_path
3292+
):
3293+
"""``databook`` names the DataBook; it is Markdown, written to disk as the
3294+
bytes that arrived, and with no filename from the server it lands as
3295+
``.databook.md``, never ``.tavi.json``."""
3296+
body = "---\nid: x\n---\n\n# Acme — 10-K\n".encode()
3297+
artifact = self._mock_artifact(body, "")
3298+
artifact.headers = {}
3299+
self._patch_httpx(mock_client_cls, artifact)
3300+
with patch.object(
3301+
LedgerClient,
3302+
"_query",
3303+
return_value=self._gql_data("text/markdown; charset=utf-8", "databook", gen=3),
3304+
) as mock_query:
3305+
result = LedgerClient(mock_config).download_report_bundle(
3306+
graph_id, "rpt_01", format="databook", to=tmp_path / "report.databook.md"
3307+
)
3308+
3309+
assert mock_query.call_args.args[2]["format"] == "DATABOOK"
3310+
assert result.format == "databook"
3311+
assert result.content_type == "text/markdown; charset=utf-8"
3312+
assert result.filename == "rpt_01-g3.databook.md"
3313+
assert (tmp_path / "report.databook.md").read_bytes() == body
3314+
32893315
@patch("robosystems_client.clients.ledger_client.httpx.Client")
32903316
def test_xbrl_download_follows_presigned_url(
32913317
self, mock_client_cls, mock_config, graph_id

0 commit comments

Comments
 (0)