filingstudio 0.4.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {filingstudio-0.4.0 → filingstudio-0.6.0}/PKG-INFO +11 -1
- {filingstudio-0.4.0 → filingstudio-0.6.0}/README.md +10 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/filingstudio/__init__.py +1 -1
- {filingstudio-0.4.0 → filingstudio-0.6.0}/filingstudio/client.py +164 -10
- {filingstudio-0.4.0 → filingstudio-0.6.0}/pyproject.toml +1 -1
- {filingstudio-0.4.0 → filingstudio-0.6.0}/tests/test_client.py +108 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/.gitignore +0 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/LICENSE +0 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/filingstudio/errors.py +0 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/filingstudio/models.py +0 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/filingstudio/research.py +0 -0
- {filingstudio-0.4.0 → filingstudio-0.6.0}/tests/test_research.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: filingstudio
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Client for the Filing Studio API: search SEC filings, resolve traces, verify claims. One call per door, typed results, your key never in a URL.
|
|
5
5
|
Project-URL: Homepage, https://filingstudio.com
|
|
6
6
|
Project-URL: Documentation, https://filingstudio.com/docs#sdk
|
|
@@ -81,6 +81,16 @@ async with AsyncFilingStudio(api_key=key) as fs:
|
|
|
81
81
|
| `filings(ticker, form=, year=, limit=)` | a company's indexed filings |
|
|
82
82
|
| `coverage(ticker)` | is anything indexed, and how fresh |
|
|
83
83
|
| `table(ticker, accession, table_id, format="records")` | one printed table, as filed |
|
|
84
|
+
| `kpi_tables(ticker, quarterly=False)` | the newest 10-K's (10-Q's) non-statement tables, as a dict |
|
|
85
|
+
| `kpi_series(ticker, table_id, quarterly=False, years=10)` | one table across filings as rows x periods, as a dict |
|
|
86
|
+
| `statement(ticker, kind, quarterly=False, years=10)` | `income`, `balance` or `cashflow` as a time series, as a dict |
|
|
87
|
+
| `filing_html(ticker, accession)` | the whole filing as sanitized HTML (str) |
|
|
88
|
+
| `filing_tables(ticker, accession)` | every printed table in the filing (list) |
|
|
89
|
+
| `exhibits(ticker, accession)` | the exhibits that carry tables (list) |
|
|
90
|
+
| `similar(ticker, accession, table_id, targets)` | the same table in other filings (list) |
|
|
91
|
+
| `table_xlsx(ticker, accession, table_id)` | one printed table as an Excel file (bytes) |
|
|
92
|
+
| `compare_targets(ticker, accession)` | older same-form filings to compare against (list) |
|
|
93
|
+
| `compare_html(ticker, accession, target=None)` | a word-level redline against an older filing (str) |
|
|
84
94
|
|
|
85
95
|
Pass `value` to `verify` as the raw figure you hold (130497 or 130497000000
|
|
86
96
|
alike). The API tries every printed scale a filer could use. Do not pre-scale.
|
|
@@ -48,6 +48,16 @@ async with AsyncFilingStudio(api_key=key) as fs:
|
|
|
48
48
|
| `filings(ticker, form=, year=, limit=)` | a company's indexed filings |
|
|
49
49
|
| `coverage(ticker)` | is anything indexed, and how fresh |
|
|
50
50
|
| `table(ticker, accession, table_id, format="records")` | one printed table, as filed |
|
|
51
|
+
| `kpi_tables(ticker, quarterly=False)` | the newest 10-K's (10-Q's) non-statement tables, as a dict |
|
|
52
|
+
| `kpi_series(ticker, table_id, quarterly=False, years=10)` | one table across filings as rows x periods, as a dict |
|
|
53
|
+
| `statement(ticker, kind, quarterly=False, years=10)` | `income`, `balance` or `cashflow` as a time series, as a dict |
|
|
54
|
+
| `filing_html(ticker, accession)` | the whole filing as sanitized HTML (str) |
|
|
55
|
+
| `filing_tables(ticker, accession)` | every printed table in the filing (list) |
|
|
56
|
+
| `exhibits(ticker, accession)` | the exhibits that carry tables (list) |
|
|
57
|
+
| `similar(ticker, accession, table_id, targets)` | the same table in other filings (list) |
|
|
58
|
+
| `table_xlsx(ticker, accession, table_id)` | one printed table as an Excel file (bytes) |
|
|
59
|
+
| `compare_targets(ticker, accession)` | older same-form filings to compare against (list) |
|
|
60
|
+
| `compare_html(ticker, accession, target=None)` | a word-level redline against an older filing (str) |
|
|
51
61
|
|
|
52
62
|
Pass `value` to `verify` as the raw figure you hold (130497 or 130497000000
|
|
53
63
|
alike). The API tries every printed scale a filer could use. Do not pre-scale.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"""
|
|
2
2
|
The Filing Studio client, sync and async. One method per /v1 door, the same
|
|
3
|
-
names as the Node `@filingstudio/client` and the browser `ProvenanceClient
|
|
3
|
+
names as the Node `@filingstudio/client` and the browser `ProvenanceClient`,
|
|
4
|
+
plus research doors (kpi_tables, kpi_series, statement) and reader doors
|
|
5
|
+
(filing_html, filing_tables, exhibits, similar, table_xlsx, compare_targets,
|
|
6
|
+
compare_html) that answer plain dicts, lists, text, or bytes.
|
|
4
7
|
|
|
5
8
|
from filingstudio import FilingStudio
|
|
6
9
|
fs = FilingStudio(api_key=os.environ["FILING_STUDIO_API_KEY"])
|
|
@@ -17,7 +20,7 @@ from __future__ import annotations
|
|
|
17
20
|
|
|
18
21
|
import random
|
|
19
22
|
import time
|
|
20
|
-
from typing import Any, Dict, Optional
|
|
23
|
+
from typing import Any, Dict, List, Optional, Sequence
|
|
21
24
|
from urllib.parse import quote
|
|
22
25
|
|
|
23
26
|
import anyio
|
|
@@ -36,6 +39,7 @@ from .models import (
|
|
|
36
39
|
)
|
|
37
40
|
|
|
38
41
|
DEFAULT_BASE = "https://api.filingstudio.com"
|
|
42
|
+
STATEMENT_KINDS = ("income", "balance", "cashflow")
|
|
39
43
|
|
|
40
44
|
|
|
41
45
|
def _clean(params: Dict[str, Any]) -> Dict[str, Any]:
|
|
@@ -50,6 +54,9 @@ def _describe(status: int, body: Any) -> "tuple[str, Optional[str]]":
|
|
|
50
54
|
msg = err.get("message") if isinstance(err.get("message"), str) else f"HTTP {status}"
|
|
51
55
|
code = err.get("code") if isinstance(err.get("code"), str) else None
|
|
52
56
|
return msg, code
|
|
57
|
+
detail = body.get("detail") if isinstance(body, dict) else None
|
|
58
|
+
if isinstance(detail, str):
|
|
59
|
+
return detail, None
|
|
53
60
|
return f"HTTP {status}", None
|
|
54
61
|
|
|
55
62
|
|
|
@@ -179,6 +186,41 @@ class _Base:
|
|
|
179
186
|
return (f"/v1/tables/{quote(ticker.upper(), safe='')}/{quote(accession, safe='')}/"
|
|
180
187
|
f"{quote(table_id, safe='')}")
|
|
181
188
|
|
|
189
|
+
# The research doors answer the raw research JSON, not the /v1 envelope.
|
|
190
|
+
|
|
191
|
+
@staticmethod
|
|
192
|
+
def _kpi_tables_path(ticker: str) -> str:
|
|
193
|
+
return f"/api/research/kpi/tables/{quote(ticker.upper(), safe='')}"
|
|
194
|
+
|
|
195
|
+
@staticmethod
|
|
196
|
+
def _kpi_series_path(ticker: str) -> str:
|
|
197
|
+
return f"/api/research/kpi/series/{quote(ticker.upper(), safe='')}"
|
|
198
|
+
|
|
199
|
+
@staticmethod
|
|
200
|
+
def _filing_path(ticker: str, accession: str) -> str:
|
|
201
|
+
return f"/{quote(ticker.upper(), safe='')}/{quote(accession, safe='')}"
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def _data_list(body: Any, key: str) -> List[Dict[str, Any]]:
|
|
205
|
+
env = body if isinstance(body, dict) else {}
|
|
206
|
+
data = env["data"] if isinstance(env.get("data"), dict) else env
|
|
207
|
+
out = data.get(key) or []
|
|
208
|
+
return [x for x in out if isinstance(x, dict)] if isinstance(out, list) else []
|
|
209
|
+
|
|
210
|
+
@staticmethod
|
|
211
|
+
def _similar(body: Any) -> List[Dict[str, Any]]:
|
|
212
|
+
env = body if isinstance(body, dict) else {}
|
|
213
|
+
data = env["data"] if isinstance(env.get("data"), dict) else env
|
|
214
|
+
hits = data.get("targets") or data.get("results") or []
|
|
215
|
+
return [{**h, "tableId": h.get("tableId", h.get("table_id"))}
|
|
216
|
+
for h in hits if isinstance(h, dict) and h.get("accession")]
|
|
217
|
+
|
|
218
|
+
@staticmethod
|
|
219
|
+
def _statement_path(ticker: str, kind: str) -> str:
|
|
220
|
+
if kind not in STATEMENT_KINDS:
|
|
221
|
+
raise ValueError(f"kind is one of {', '.join(STATEMENT_KINDS)}")
|
|
222
|
+
return f"/api/research/statements/{quote(ticker.upper(), safe='')}/{kind}"
|
|
223
|
+
|
|
182
224
|
|
|
183
225
|
class FilingStudio(_Base):
|
|
184
226
|
"""Synchronous client. Use as a context manager to reuse one connection."""
|
|
@@ -198,8 +240,8 @@ class FilingStudio(_Base):
|
|
|
198
240
|
def __exit__(self, *exc: object) -> None:
|
|
199
241
|
self.close()
|
|
200
242
|
|
|
201
|
-
def
|
|
202
|
-
|
|
243
|
+
def _send(self, method: str, path: str, *, params: Optional[Dict[str, Any]] = None,
|
|
244
|
+
json: Any = None) -> httpx.Response:
|
|
203
245
|
last: Optional[BaseException] = None
|
|
204
246
|
for attempt in range(self._max_retries + 1):
|
|
205
247
|
if attempt:
|
|
@@ -210,9 +252,9 @@ class FilingStudio(_Base):
|
|
|
210
252
|
except httpx.TransportError as exc:
|
|
211
253
|
last = exc
|
|
212
254
|
continue
|
|
213
|
-
body = self._parse(res)
|
|
214
255
|
if res.is_success:
|
|
215
|
-
return
|
|
256
|
+
return res
|
|
257
|
+
body = self._parse(res)
|
|
216
258
|
if res.status_code >= 500:
|
|
217
259
|
last = FilingStudioError(res.status_code, _describe(res.status_code, body)[0], None, body)
|
|
218
260
|
continue
|
|
@@ -221,6 +263,11 @@ class FilingStudio(_Base):
|
|
|
221
263
|
raise last
|
|
222
264
|
raise self._unreachable(last)
|
|
223
265
|
|
|
266
|
+
def _request(self, method: str, path: str, *, params: Optional[Dict[str, Any]] = None,
|
|
267
|
+
json: Any = None) -> Any:
|
|
268
|
+
body = self._parse(self._send(method, path, params=params, json=json))
|
|
269
|
+
return body if body is not None else {}
|
|
270
|
+
|
|
224
271
|
def search(self, ticker: str, q: str, *, type: Optional[str] = None, period: Optional[str] = None,
|
|
225
272
|
forms: Optional[str] = None, limit: Optional[int] = None,
|
|
226
273
|
offset: Optional[int] = None) -> SearchResult:
|
|
@@ -258,6 +305,65 @@ class FilingStudio(_Base):
|
|
|
258
305
|
return self._table(self._request("GET", self._table_path(ticker, accession, table_id),
|
|
259
306
|
params={"format": format}))
|
|
260
307
|
|
|
308
|
+
def kpi_tables(self, ticker: str, *, quarterly: bool = False) -> Dict[str, Any]:
|
|
309
|
+
"""The newest 10-K's (10-Q's) non-statement tables, named by the text above them:
|
|
310
|
+
{ticker, accession, form, filed, tables}."""
|
|
311
|
+
return self._request("GET", self._kpi_tables_path(ticker), params={"quarterly": quarterly})
|
|
312
|
+
|
|
313
|
+
def kpi_series(self, ticker: str, table_id: str, *, quarterly: bool = False,
|
|
314
|
+
years: int = 10) -> Dict[str, Any]:
|
|
315
|
+
"""One printed table carried across filings as rows x periods, every value traced:
|
|
316
|
+
{ticker, tableId, above, units, periods, sources, rows, gaps}."""
|
|
317
|
+
return self._request("GET", self._kpi_series_path(ticker),
|
|
318
|
+
params={"table_id": table_id, "quarterly": quarterly, "years": years})
|
|
319
|
+
|
|
320
|
+
def statement(self, ticker: str, kind: str, *, quarterly: bool = False,
|
|
321
|
+
years: int = 10) -> Dict[str, Any]:
|
|
322
|
+
"""A primary statement (income, balance, cashflow) as a time series from each
|
|
323
|
+
filing's printed table. No model."""
|
|
324
|
+
return self._request("GET", self._statement_path(ticker, kind),
|
|
325
|
+
params={"quarterly": quarterly, "years": years})
|
|
326
|
+
|
|
327
|
+
# ---- the reader: one filing, its documents and tables ----------------------
|
|
328
|
+
|
|
329
|
+
def filing_html(self, ticker: str, accession: str) -> str:
|
|
330
|
+
"""The whole filing as sanitized HTML, ready for an iframe."""
|
|
331
|
+
return self._send("GET", f"/api/filings{self._filing_path(ticker, accession)}/html").text
|
|
332
|
+
|
|
333
|
+
def filing_tables(self, ticker: str, accession: str) -> List[Dict[str, Any]]:
|
|
334
|
+
"""Every printed table in one filing: id, heading, size, periods."""
|
|
335
|
+
return self._data_list(
|
|
336
|
+
self._request("GET", f"/v1/filings{self._filing_path(ticker, accession)}/tables"), "tables")
|
|
337
|
+
|
|
338
|
+
def exhibits(self, ticker: str, accession: str) -> List[Dict[str, Any]]:
|
|
339
|
+
"""The filing's exhibits that carry tables, with their table ids."""
|
|
340
|
+
return self._data_list(
|
|
341
|
+
self._request("GET", f"/v1/filings{self._filing_path(ticker, accession)}/exhibits"), "exhibits")
|
|
342
|
+
|
|
343
|
+
def similar(self, ticker: str, accession: str, table_id: str,
|
|
344
|
+
targets: Sequence[str]) -> List[Dict[str, Any]]:
|
|
345
|
+
"""The same printed table in other filings (target accessions). One entry per
|
|
346
|
+
target: `tableId` is None where nothing matched, `matchedBy` and `why` say how it did."""
|
|
347
|
+
if not targets:
|
|
348
|
+
return []
|
|
349
|
+
return self._similar(self._request("GET", self._table_path(ticker, accession, table_id) + "/same-in",
|
|
350
|
+
params={"targets": ",".join(targets)}))
|
|
351
|
+
|
|
352
|
+
def table_xlsx(self, ticker: str, accession: str, table_id: str) -> bytes:
|
|
353
|
+
"""One printed table as an Excel workbook."""
|
|
354
|
+
return self._send("GET", self._table_path(ticker, accession, table_id) + "/xlsx").content
|
|
355
|
+
|
|
356
|
+
def compare_targets(self, ticker: str, accession: str) -> List[Dict[str, Any]]:
|
|
357
|
+
"""Older filings of the same form this one can be compared against, newest first."""
|
|
358
|
+
return self._data_list(
|
|
359
|
+
self._request("GET", f"/api/filings{self._filing_path(ticker, accession)}/compare-targets"), "targets")
|
|
360
|
+
|
|
361
|
+
def compare_html(self, ticker: str, accession: str, target: Optional[str] = None) -> str:
|
|
362
|
+
"""A word-level redline of this filing against `target` (default: the prior
|
|
363
|
+
filing of the same form), as HTML."""
|
|
364
|
+
return self._send("GET", f"/api/filings{self._filing_path(ticker, accession)}/compare-filing",
|
|
365
|
+
params=_clean({"target": target})).text
|
|
366
|
+
|
|
261
367
|
|
|
262
368
|
class AsyncFilingStudio(_Base):
|
|
263
369
|
"""Asynchronous client with the same methods."""
|
|
@@ -277,8 +383,8 @@ class AsyncFilingStudio(_Base):
|
|
|
277
383
|
async def __aexit__(self, *exc: object) -> None:
|
|
278
384
|
await self.aclose()
|
|
279
385
|
|
|
280
|
-
async def
|
|
281
|
-
|
|
386
|
+
async def _send(self, method: str, path: str, *, params: Optional[Dict[str, Any]] = None,
|
|
387
|
+
json: Any = None) -> httpx.Response:
|
|
282
388
|
last: Optional[BaseException] = None
|
|
283
389
|
for attempt in range(self._max_retries + 1):
|
|
284
390
|
if attempt:
|
|
@@ -289,9 +395,9 @@ class AsyncFilingStudio(_Base):
|
|
|
289
395
|
except httpx.TransportError as exc:
|
|
290
396
|
last = exc
|
|
291
397
|
continue
|
|
292
|
-
body = self._parse(res)
|
|
293
398
|
if res.is_success:
|
|
294
|
-
return
|
|
399
|
+
return res
|
|
400
|
+
body = self._parse(res)
|
|
295
401
|
if res.status_code >= 500:
|
|
296
402
|
last = FilingStudioError(res.status_code, _describe(res.status_code, body)[0], None, body)
|
|
297
403
|
continue
|
|
@@ -300,6 +406,11 @@ class AsyncFilingStudio(_Base):
|
|
|
300
406
|
raise last
|
|
301
407
|
raise self._unreachable(last)
|
|
302
408
|
|
|
409
|
+
async def _request(self, method: str, path: str, *, params: Optional[Dict[str, Any]] = None,
|
|
410
|
+
json: Any = None) -> Any:
|
|
411
|
+
body = self._parse(await self._send(method, path, params=params, json=json))
|
|
412
|
+
return body if body is not None else {}
|
|
413
|
+
|
|
303
414
|
async def search(self, ticker: str, q: str, *, type: Optional[str] = None,
|
|
304
415
|
period: Optional[str] = None, forms: Optional[str] = None,
|
|
305
416
|
limit: Optional[int] = None, offset: Optional[int] = None) -> SearchResult:
|
|
@@ -331,3 +442,46 @@ class AsyncFilingStudio(_Base):
|
|
|
331
442
|
format: str = "records") -> TableResult:
|
|
332
443
|
return self._table(await self._request("GET", self._table_path(ticker, accession, table_id),
|
|
333
444
|
params={"format": format}))
|
|
445
|
+
|
|
446
|
+
async def kpi_tables(self, ticker: str, *, quarterly: bool = False) -> Dict[str, Any]:
|
|
447
|
+
return await self._request("GET", self._kpi_tables_path(ticker), params={"quarterly": quarterly})
|
|
448
|
+
|
|
449
|
+
async def kpi_series(self, ticker: str, table_id: str, *, quarterly: bool = False,
|
|
450
|
+
years: int = 10) -> Dict[str, Any]:
|
|
451
|
+
return await self._request("GET", self._kpi_series_path(ticker),
|
|
452
|
+
params={"table_id": table_id, "quarterly": quarterly, "years": years})
|
|
453
|
+
|
|
454
|
+
async def statement(self, ticker: str, kind: str, *, quarterly: bool = False,
|
|
455
|
+
years: int = 10) -> Dict[str, Any]:
|
|
456
|
+
return await self._request("GET", self._statement_path(ticker, kind),
|
|
457
|
+
params={"quarterly": quarterly, "years": years})
|
|
458
|
+
|
|
459
|
+
async def filing_html(self, ticker: str, accession: str) -> str:
|
|
460
|
+
return (await self._send("GET", f"/api/filings{self._filing_path(ticker, accession)}/html")).text
|
|
461
|
+
|
|
462
|
+
async def filing_tables(self, ticker: str, accession: str) -> List[Dict[str, Any]]:
|
|
463
|
+
return self._data_list(
|
|
464
|
+
await self._request("GET", f"/v1/filings{self._filing_path(ticker, accession)}/tables"), "tables")
|
|
465
|
+
|
|
466
|
+
async def exhibits(self, ticker: str, accession: str) -> List[Dict[str, Any]]:
|
|
467
|
+
return self._data_list(
|
|
468
|
+
await self._request("GET", f"/v1/filings{self._filing_path(ticker, accession)}/exhibits"), "exhibits")
|
|
469
|
+
|
|
470
|
+
async def similar(self, ticker: str, accession: str, table_id: str,
|
|
471
|
+
targets: Sequence[str]) -> List[Dict[str, Any]]:
|
|
472
|
+
if not targets:
|
|
473
|
+
return []
|
|
474
|
+
return self._similar(await self._request("GET", self._table_path(ticker, accession, table_id) + "/same-in",
|
|
475
|
+
params={"targets": ",".join(targets)}))
|
|
476
|
+
|
|
477
|
+
async def table_xlsx(self, ticker: str, accession: str, table_id: str) -> bytes:
|
|
478
|
+
return (await self._send("GET", self._table_path(ticker, accession, table_id) + "/xlsx")).content
|
|
479
|
+
|
|
480
|
+
async def compare_targets(self, ticker: str, accession: str) -> List[Dict[str, Any]]:
|
|
481
|
+
return self._data_list(
|
|
482
|
+
await self._request("GET", f"/api/filings{self._filing_path(ticker, accession)}/compare-targets"),
|
|
483
|
+
"targets")
|
|
484
|
+
|
|
485
|
+
async def compare_html(self, ticker: str, accession: str, target: Optional[str] = None) -> str:
|
|
486
|
+
return (await self._send("GET", f"/api/filings{self._filing_path(ticker, accession)}/compare-filing",
|
|
487
|
+
params=_clean({"target": target}))).text
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "filingstudio"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.6.0"
|
|
8
8
|
description = "Client for the Filing Studio API: search SEC filings, resolve traces, verify claims. One call per door, typed results, your key never in a URL."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -207,3 +207,111 @@ async def test_async_client_mirrors_sync():
|
|
|
207
207
|
v = await fs.verify("NVDA", metric="Revenue", value=1)
|
|
208
208
|
assert v.verdict == "unsupported" and v.actual[0].printed_text == "130,497"
|
|
209
209
|
assert seen[-1].headers["x-api-key"] == KEY
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def test_research_doors_paths_params_and_raw_json():
|
|
213
|
+
fs, seen = make(lambda r, n: ok({"ticker": "LEN", "tables": [{"tableId": "t1"}]}))
|
|
214
|
+
assert fs.kpi_tables("len", quarterly=True)["tables"][0]["tableId"] == "t1"
|
|
215
|
+
fs.kpi_series("len", "primary:83", years=5)
|
|
216
|
+
fs.statement("len", "cashflow", quarterly=True, years=3)
|
|
217
|
+
assert [r.url.path for r in seen] == [
|
|
218
|
+
"/api/research/kpi/tables/LEN",
|
|
219
|
+
"/api/research/kpi/series/LEN",
|
|
220
|
+
"/api/research/statements/LEN/cashflow",
|
|
221
|
+
]
|
|
222
|
+
assert dict(seen[0].url.params) == {"quarterly": "true"}
|
|
223
|
+
assert dict(seen[1].url.params) == {"table_id": "primary:83", "quarterly": "false", "years": "5"}
|
|
224
|
+
assert dict(seen[2].url.params) == {"quarterly": "true", "years": "3"}
|
|
225
|
+
assert all(r.headers["x-api-key"] == KEY and KEY not in str(r.url) for r in seen)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def test_statement_rejects_unknown_kind_before_calling():
|
|
229
|
+
fs, seen = make(lambda r, n: ok({}))
|
|
230
|
+
with pytest.raises(ValueError):
|
|
231
|
+
fs.statement("LEN", "equity")
|
|
232
|
+
assert seen == []
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def test_research_door_404_detail_becomes_the_message():
|
|
236
|
+
fs, _ = make(lambda r, n: httpx.Response(404, json={"detail": "No 10-K for ZZZZ"}))
|
|
237
|
+
with pytest.raises(FilingStudioError) as e:
|
|
238
|
+
fs.kpi_tables("ZZZZ")
|
|
239
|
+
assert e.value.status == 404
|
|
240
|
+
assert "No 10-K for ZZZZ" in str(e.value)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@pytest.mark.anyio
|
|
244
|
+
async def test_async_research_doors():
|
|
245
|
+
fs, seen = amake(lambda r, n: ok({"rows": []}))
|
|
246
|
+
assert await fs.statement("nvda", "income") == {"rows": []}
|
|
247
|
+
await fs.kpi_series("nvda", "t9")
|
|
248
|
+
await fs.kpi_tables("nvda")
|
|
249
|
+
assert [r.url.path for r in seen] == [
|
|
250
|
+
"/api/research/statements/NVDA/income",
|
|
251
|
+
"/api/research/kpi/series/NVDA",
|
|
252
|
+
"/api/research/kpi/tables/NVDA",
|
|
253
|
+
]
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
ACC = "0000882184-26-000123"
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def test_reader_doors_paths_and_shapes():
|
|
260
|
+
def h(r, n):
|
|
261
|
+
p = r.url.path
|
|
262
|
+
if p.endswith("/html") or p.endswith("/compare-filing"):
|
|
263
|
+
return httpx.Response(200, text="<html>filing</html>", headers={"content-type": "text/html"})
|
|
264
|
+
if p.endswith("/xlsx"):
|
|
265
|
+
return httpx.Response(200, content=b"PK\x03\x04")
|
|
266
|
+
if p.endswith("/tables"):
|
|
267
|
+
return ok({"data": {"tables": [{"id": "primary:1"}]}})
|
|
268
|
+
if p.endswith("/exhibits"):
|
|
269
|
+
return ok({"exhibits": [{"exhibit": "EX-99.1", "tableIds": ["exhibit:3"]}]})
|
|
270
|
+
if p.endswith("/same-in"):
|
|
271
|
+
return ok({"data": {"targets": [{"accession": "A1", "table_id": "primary:9"}, {"accession": "A2"}]}})
|
|
272
|
+
if p.endswith("/compare-targets"):
|
|
273
|
+
return ok({"targets": [{"accession": "A1"}]})
|
|
274
|
+
return httpx.Response(404, json={"detail": "nope"})
|
|
275
|
+
|
|
276
|
+
fs, seen = make(h)
|
|
277
|
+
assert fs.filing_html("dhi", ACC) == "<html>filing</html>"
|
|
278
|
+
assert fs.filing_tables("dhi", ACC) == [{"id": "primary:1"}]
|
|
279
|
+
assert fs.exhibits("dhi", ACC)[0]["exhibit"] == "EX-99.1"
|
|
280
|
+
hits = fs.similar("dhi", ACC, "primary:1", ["A1", "A2"])
|
|
281
|
+
assert [(x["accession"], x["tableId"]) for x in hits] == [("A1", "primary:9"), ("A2", None)]
|
|
282
|
+
assert fs.table_xlsx("dhi", ACC, "primary:1") == b"PK\x03\x04"
|
|
283
|
+
assert fs.compare_targets("dhi", ACC) == [{"accession": "A1"}]
|
|
284
|
+
assert fs.compare_html("dhi", ACC, target="A1") == "<html>filing</html>"
|
|
285
|
+
assert fs.similar("dhi", ACC, "primary:1", []) == []
|
|
286
|
+
paths = [r.url.path for r in seen]
|
|
287
|
+
assert paths == [
|
|
288
|
+
f"/api/filings/DHI/{ACC}/html",
|
|
289
|
+
f"/v1/filings/DHI/{ACC}/tables",
|
|
290
|
+
f"/v1/filings/DHI/{ACC}/exhibits",
|
|
291
|
+
f"/v1/tables/DHI/{ACC}/primary:1/same-in",
|
|
292
|
+
f"/v1/tables/DHI/{ACC}/primary:1/xlsx",
|
|
293
|
+
f"/api/filings/DHI/{ACC}/compare-targets",
|
|
294
|
+
f"/api/filings/DHI/{ACC}/compare-filing",
|
|
295
|
+
]
|
|
296
|
+
assert dict(seen[3].url.params) == {"targets": "A1,A2"}
|
|
297
|
+
assert dict(seen[6].url.params) == {"target": "A1"}
|
|
298
|
+
assert all(r.headers["x-api-key"] == KEY and KEY not in str(r.url) for r in seen)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def test_filing_html_404_raises():
|
|
302
|
+
fs, _ = make(lambda r, n: httpx.Response(404, json={"detail": "Filing not available"}))
|
|
303
|
+
with pytest.raises(FilingStudioError) as e:
|
|
304
|
+
fs.filing_html("DHI", ACC)
|
|
305
|
+
assert e.value.message == "Filing not available"
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
@pytest.mark.anyio
|
|
309
|
+
async def test_async_reader_doors():
|
|
310
|
+
def h(r, n):
|
|
311
|
+
if r.url.path.endswith("/html"):
|
|
312
|
+
return httpx.Response(200, text="<p>x</p>")
|
|
313
|
+
return ok({"data": {"targets": [{"accession": "A1", "tableId": "primary:2"}]}})
|
|
314
|
+
|
|
315
|
+
fs, seen = amake(h)
|
|
316
|
+
assert await fs.filing_html("dhi", ACC) == "<p>x</p>"
|
|
317
|
+
assert (await fs.similar("dhi", ACC, "primary:1", ["A1"]))[0]["tableId"] == "primary:2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|