fd-open-data-protocol 0.5.1__tar.gz → 0.5.4__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.
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/PKG-INFO +2 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/__init__.py +1 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/__init__.py +2 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/wellknown.py +43 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/concepts.yaml +1 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/crosswalks/datacommons-worldbank.yaml +1 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/entity_types.yaml +114 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/event_types.yaml +1 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/qualifiers.yaml +1 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/relation_types.yaml +1 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/units.yaml +11 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary.py +30 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/PKG-INFO +2 -1
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/SOURCES.txt +1 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/requires.txt +1 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/pyproject.toml +1 -1
- fd_open_data_protocol-0.5.4/tests/test_drift_inventory.py +49 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_line_ops.py +69 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_vocabulary.py +14 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_vocabulary_additive.py +17 -2
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/LICENSE +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/README.md +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/conformance_adapter.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/constants.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/assemble.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/auth_gate.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/client.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/config.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/loader.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/openalex_provider.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/provider.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/registry.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/registry_cli.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/registry_store.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/schema.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/surface_report.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/surface_selfcheck.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary/alignment/foundation.yaml +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/dependency_links.txt +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/entry_points.txt +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/top_level.txt +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/setup.cfg +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_loader.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_openalex_provider.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_registry_pipeline.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_registry_schema.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_schema_vocabulary.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_surface_report.py +0 -0
- {fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_surface_selfcheck.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fd-open-data-protocol
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.4
|
|
4
4
|
Summary: The open-data datasource protocol: a manifest contract a datasource exposes to be ingested by fd-open-data-mcp (or any consumer).
|
|
5
5
|
Author: FindDataOfficial
|
|
6
6
|
License: MIT
|
|
@@ -15,6 +15,7 @@ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
|
15
15
|
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
16
16
|
Provides-Extra: line-ops
|
|
17
17
|
Requires-Dist: httpx>=0.27; extra == "line-ops"
|
|
18
|
+
Requires-Dist: starlette>=0.27; extra == "line-ops"
|
|
18
19
|
Provides-Extra: registry
|
|
19
20
|
Requires-Dist: psycopg[binary]>=3.1; extra == "registry"
|
|
20
21
|
Dynamic: license-file
|
|
@@ -28,7 +28,7 @@ from .assemble import assemble
|
|
|
28
28
|
from .auth_gate import AuthGate, AuthGateMiddleware, bearer_from_scope
|
|
29
29
|
from .client import LineClient, LineError
|
|
30
30
|
from .config import LineSettings, make_settings_class
|
|
31
|
-
from .wellknown import WELL_KNOWN_PATH, manifest_response
|
|
31
|
+
from .wellknown import WELL_KNOWN_PATH, manifest_response, register
|
|
32
32
|
|
|
33
33
|
__all__ = [
|
|
34
34
|
"assemble",
|
|
@@ -41,4 +41,5 @@ __all__ = [
|
|
|
41
41
|
"make_settings_class",
|
|
42
42
|
"WELL_KNOWN_PATH",
|
|
43
43
|
"manifest_response",
|
|
44
|
+
"register",
|
|
44
45
|
]
|
|
@@ -70,3 +70,46 @@ def manifest_response(anchor: Path | str | None = None) -> tuple[int, bytes, lis
|
|
|
70
70
|
return 200, raw, json_headers + [
|
|
71
71
|
(b"cache-control", MANIFEST_CACHE_CONTROL.encode()),
|
|
72
72
|
]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def register(mcp, anchor: Path | str | None = None) -> None:
|
|
76
|
+
"""Mount the endpoint on a FastMCP instance (stdio has no HTTP face, so skip).
|
|
77
|
+
|
|
78
|
+
``custom_route`` is used rather than wrapping ASGI so the route exists in
|
|
79
|
+
both HTTP branches (bearer gate on or off). The auth gate's exempt-path list
|
|
80
|
+
must include ``WELL_KNOWN_PATH`` too, otherwise a line with a token returns
|
|
81
|
+
401 to anonymous discovery.
|
|
82
|
+
|
|
83
|
+
:param anchor: pass the consuming repo's own ``__file__`` (usually from its
|
|
84
|
+
``wellknown.py`` adapter) so the manifest candidate chain resolves
|
|
85
|
+
against that repo, not against this shared package.
|
|
86
|
+
"""
|
|
87
|
+
from starlette.responses import Response # only the HTTP branch needs it
|
|
88
|
+
|
|
89
|
+
def _response() -> "Response":
|
|
90
|
+
status, body, extra = manifest_response(anchor)
|
|
91
|
+
headers = {k.decode(): v.decode() for k, v in extra}
|
|
92
|
+
return Response(
|
|
93
|
+
content=body,
|
|
94
|
+
status_code=status,
|
|
95
|
+
media_type="application/json; charset=utf-8",
|
|
96
|
+
headers=headers,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if hasattr(mcp, "custom_route"):
|
|
100
|
+
@mcp.custom_route(WELL_KNOWN_PATH, methods=["GET"])
|
|
101
|
+
async def line_manifest(_request): # noqa: ANN001 - ASGI boundary
|
|
102
|
+
return _response()
|
|
103
|
+
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
if hasattr(mcp, "get"):
|
|
107
|
+
@mcp.get(WELL_KNOWN_PATH, include_in_schema=False)
|
|
108
|
+
async def line_manifest_route():
|
|
109
|
+
return _response()
|
|
110
|
+
|
|
111
|
+
return
|
|
112
|
+
|
|
113
|
+
raise RuntimeError(
|
|
114
|
+
"应用既没有 custom_route 也没有 get:无法挂 " + WELL_KNOWN_PATH + "(别静默跳过)"
|
|
115
|
+
)
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#
|
|
11
11
|
# URIs for the mapped Variables themselves are Phase 4; this release carries
|
|
12
12
|
# only family URIs.
|
|
13
|
-
version: "2026.
|
|
13
|
+
version: "2026.12"
|
|
14
14
|
kind: crosswalk
|
|
15
15
|
mappings:
|
|
16
16
|
# --- Population -------------------------------------------------------------
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# URIs: https://schema.finddata.tech/entity-type/<id>
|
|
8
8
|
#
|
|
9
9
|
# Entries are never deleted — retirement is expressed with `superseded_by`.
|
|
10
|
-
version: "2026.
|
|
10
|
+
version: "2026.12"
|
|
11
11
|
kind: entity-type
|
|
12
12
|
entries:
|
|
13
13
|
- id: country
|
|
@@ -23,6 +23,14 @@ entries:
|
|
|
23
23
|
description: >-
|
|
24
24
|
Municipalities and administrative cities (beijing, shanghai). Aligns with
|
|
25
25
|
schema.org City and Data Commons City, anchored by DCID or GeoNames id.
|
|
26
|
+
- id: province
|
|
27
|
+
label_en: Province
|
|
28
|
+
label_zh: 省级行政区
|
|
29
|
+
description: >-
|
|
30
|
+
First-level administrative divisions of mainland China (北京市, 广东省,
|
|
31
|
+
内蒙古自治区), keyed by the 12-digit NBS/GB administrative code. Distinct
|
|
32
|
+
from city: province-level statistics (e.g. 分省年度平均工资) must not be
|
|
33
|
+
coerced into city entities.
|
|
26
34
|
- id: stock
|
|
27
35
|
label_en: Stock
|
|
28
36
|
label_zh: 股票
|
|
@@ -219,3 +227,108 @@ entries:
|
|
|
219
227
|
parsed target of a 限定支付范围 clause (限伴有出血的胃、十二指肠溃疡).
|
|
220
228
|
Keyed by a normalised indication string; kept distinct from `drug` so a
|
|
221
229
|
restriction can be compared across drugs and catalog editions.
|
|
230
|
+
# --- 2026-11-30 additive: drift-ruled real source usage (reconcile-fd-open-data-ontology P1) ---
|
|
231
|
+
- id: region
|
|
232
|
+
label_en: Region
|
|
233
|
+
label_zh: 区域
|
|
234
|
+
description: >-
|
|
235
|
+
Sub-national or statistical regions keyed by their own code; sibling to
|
|
236
|
+
country. Aligns with schema.org AdministrativeArea / Data Commons geo.
|
|
237
|
+
- id: market
|
|
238
|
+
label_en: Market
|
|
239
|
+
label_zh: 市场
|
|
240
|
+
description: >-
|
|
241
|
+
A trading or industry market (e.g. a commodity market, a stock exchange
|
|
242
|
+
market). Distinct from `venue` (a physical exchange place).
|
|
243
|
+
- id: product
|
|
244
|
+
label_en: Product
|
|
245
|
+
label_zh: 产品
|
|
246
|
+
description: >-
|
|
247
|
+
A good or product sold or tracked. Aligns with schema.org Product;
|
|
248
|
+
overlaps `item` at the foundation layer.
|
|
249
|
+
- id: world
|
|
250
|
+
label_en: World (global total)
|
|
251
|
+
label_zh: 全球
|
|
252
|
+
description: >-
|
|
253
|
+
A global/aggregate scope with no single country (world totals). Prefer
|
|
254
|
+
`region` for a sub-global area; `world` marks the global aggregate.
|
|
255
|
+
- id: location
|
|
256
|
+
label_en: Location
|
|
257
|
+
label_zh: 地点
|
|
258
|
+
description: >-
|
|
259
|
+
A generic location (point/area/venue) not resolvable to a stricter place
|
|
260
|
+
type. Aligns with schema.org Place.
|
|
261
|
+
- id: bank
|
|
262
|
+
label_en: Bank
|
|
263
|
+
label_zh: 银行
|
|
264
|
+
description: >-
|
|
265
|
+
A bank as an organisation subtype, to carry bank-specific attributes
|
|
266
|
+
without overloading `organization`.
|
|
267
|
+
- id: resource
|
|
268
|
+
label_en: Natural resource
|
|
269
|
+
label_zh: 资源
|
|
270
|
+
description: >-
|
|
271
|
+
A natural resource or resource endowment (minerals, water, arable land).
|
|
272
|
+
- id: work
|
|
273
|
+
label_en: Work
|
|
274
|
+
label_zh: 作品
|
|
275
|
+
description: >-
|
|
276
|
+
A creative work (film, book, artwork). Aligns with schema.org CreativeWork.
|
|
277
|
+
- id: bond_aggregate
|
|
278
|
+
label_en: Bond aggregate
|
|
279
|
+
label_zh: 债券聚合
|
|
280
|
+
description: >-
|
|
281
|
+
An aggregate bond figure (a cohort/index of bonds), keyed by the cohort
|
|
282
|
+
definition rather than an individual instrument.
|
|
283
|
+
- id: contract
|
|
284
|
+
label_en: Contract
|
|
285
|
+
label_zh: 合同
|
|
286
|
+
description: >-
|
|
287
|
+
A contract as a document/agreement. Aligns with foundation `agreement`.
|
|
288
|
+
- id: npl_transfer
|
|
289
|
+
label_en: NPL transfer
|
|
290
|
+
label_zh: 不良资产转让
|
|
291
|
+
description: >-
|
|
292
|
+
A non-performing-loan transfer bundle (清收/转让标的).
|
|
293
|
+
- id: bond_rating_bucket
|
|
294
|
+
label_en: Bond rating bucket
|
|
295
|
+
label_zh: 债券评级分档
|
|
296
|
+
description: >-
|
|
297
|
+
A rating bucket (AAA/AA+/…/default) used to group bonds, not an issuer.
|
|
298
|
+
- id: institution_category
|
|
299
|
+
label_en: Institution category
|
|
300
|
+
label_zh: 机构类别
|
|
301
|
+
description: >-
|
|
302
|
+
A classification axis over institutions (by type/ownership).
|
|
303
|
+
- id: organization_category
|
|
304
|
+
label_en: Organization category
|
|
305
|
+
label_zh: 组织类别
|
|
306
|
+
description: >-
|
|
307
|
+
A classification axis over organizations (by type/sector).
|
|
308
|
+
- id: movie
|
|
309
|
+
label_en: Movie
|
|
310
|
+
label_zh: 影片
|
|
311
|
+
description: >-
|
|
312
|
+
A released film title (row-office/streaming), distinct from generic `work`.
|
|
313
|
+
- id: crop_variety
|
|
314
|
+
label_en: Crop variety
|
|
315
|
+
label_zh: 作物品种
|
|
316
|
+
description: >-
|
|
317
|
+
A specific crop cultivar/variety (e.g. a rose cultivar in planted-area data).
|
|
318
|
+
- id: enterprise
|
|
319
|
+
label_en: Enterprise
|
|
320
|
+
label_zh: 企业
|
|
321
|
+
description: >-
|
|
322
|
+
An enterprise/business entity; sibling to `organization`, kept distinct
|
|
323
|
+
where the source keys by enterprise/credit registry rather than a party id.
|
|
324
|
+
- id: standard
|
|
325
|
+
label_en: Standard / specification
|
|
326
|
+
label_zh: 标准/规范
|
|
327
|
+
description: >-
|
|
328
|
+
A standard or specification document (national/industry standard).
|
|
329
|
+
- id: creator
|
|
330
|
+
label_en: Creator
|
|
331
|
+
label_zh: 创作者
|
|
332
|
+
description: >-
|
|
333
|
+
The creator/author of a work (person or body), keyed where the work has a
|
|
334
|
+
creator role distinct from the person entity.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# URIs: https://schema.finddata.tech/unit/<id>
|
|
9
9
|
#
|
|
10
10
|
# Entries are never deleted — retirement is expressed with `superseded_by`.
|
|
11
|
-
version: "2026.
|
|
11
|
+
version: "2026.12"
|
|
12
12
|
kind: unit
|
|
13
13
|
entries:
|
|
14
14
|
# --- Monetary ---------------------------------------------------------------
|
|
@@ -93,6 +93,16 @@ entries:
|
|
|
93
93
|
description: A duration measured in calendar years.
|
|
94
94
|
un_cefact_code: ANN
|
|
95
95
|
|
|
96
|
+
- id: hectare
|
|
97
|
+
label_en: Hectare
|
|
98
|
+
label_zh: 公顷
|
|
99
|
+
description: >-
|
|
100
|
+
Land area of 10 000 square metres. Used for planted/flowering area
|
|
101
|
+
cross-sections (AIPH yearbook per flower product and country).
|
|
102
|
+
Added by add-flower-vertical wave 2 (2026-11-08) because the flower
|
|
103
|
+
planted-area series had no dimension-bearing unit in this registry.
|
|
104
|
+
un_cefact_code: HAR
|
|
105
|
+
|
|
96
106
|
- id: count
|
|
97
107
|
label_en: Count
|
|
98
108
|
label_zh: 计数
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/vocabulary.py
RENAMED
|
@@ -277,6 +277,9 @@ def validate_vocabulary(dir: Optional[Union[str, Path]] = None) -> list[str]:
|
|
|
277
277
|
return [f"{d}: vocabulary directory not found"]
|
|
278
278
|
|
|
279
279
|
versions: list[tuple[str, str]] = []
|
|
280
|
+
entity_type_ids: set[str] = set()
|
|
281
|
+
entity_types_loaded = False
|
|
282
|
+
relation_refs: list[tuple[Any, str, Any]] = []
|
|
280
283
|
|
|
281
284
|
for filename in FILES.values():
|
|
282
285
|
path = d / filename
|
|
@@ -298,6 +301,33 @@ def validate_vocabulary(dir: Optional[Union[str, Path]] = None) -> list[str]:
|
|
|
298
301
|
errors.append(f"{filename}: missing required top-level 'entries'")
|
|
299
302
|
else:
|
|
300
303
|
_validate_entries(filename, data["entries"], errors)
|
|
304
|
+
if isinstance(data["entries"], list):
|
|
305
|
+
if filename == FILES["entity-type"]:
|
|
306
|
+
entity_types_loaded = True
|
|
307
|
+
for e in data["entries"]:
|
|
308
|
+
if isinstance(e, dict) and isinstance(e.get("id"), str):
|
|
309
|
+
entity_type_ids.add(e["id"])
|
|
310
|
+
elif filename == FILES["relation-type"]:
|
|
311
|
+
# Collect domain/range refs to cross-check after all files load.
|
|
312
|
+
for e in data["entries"]:
|
|
313
|
+
if isinstance(e, dict):
|
|
314
|
+
rid = e.get("id")
|
|
315
|
+
for key in ("source_types", "target_types"):
|
|
316
|
+
for t in (e.get(key) or []):
|
|
317
|
+
relation_refs.append((rid, key, t))
|
|
318
|
+
|
|
319
|
+
# Cross-set referential integrity: a relation's declared domain/range must
|
|
320
|
+
# name entity types that actually exist. These fields "describe, do not
|
|
321
|
+
# restrict" (see relation_types.yaml), so this only catches typos/dangling
|
|
322
|
+
# names — it does not constrain what a source may declare. Skipped when the
|
|
323
|
+
# entity_types file itself failed to load (empty set would be a false alarm).
|
|
324
|
+
if entity_types_loaded:
|
|
325
|
+
for rid, key, t in relation_refs:
|
|
326
|
+
if isinstance(t, str) and t not in entity_type_ids:
|
|
327
|
+
errors.append(
|
|
328
|
+
f"relation_types.yaml: relation {rid!r} {key} names unknown "
|
|
329
|
+
f"entity type {t!r}"
|
|
330
|
+
)
|
|
301
331
|
|
|
302
332
|
cw_dir = d / "crosswalks"
|
|
303
333
|
if cw_dir.is_dir():
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fd-open-data-protocol
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.4
|
|
4
4
|
Summary: The open-data datasource protocol: a manifest contract a datasource exposes to be ingested by fd-open-data-mcp (or any consumer).
|
|
5
5
|
Author: FindDataOfficial
|
|
6
6
|
License: MIT
|
|
@@ -15,6 +15,7 @@ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
|
15
15
|
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
16
16
|
Provides-Extra: line-ops
|
|
17
17
|
Requires-Dist: httpx>=0.27; extra == "line-ops"
|
|
18
|
+
Requires-Dist: starlette>=0.27; extra == "line-ops"
|
|
18
19
|
Provides-Extra: registry
|
|
19
20
|
Requires-Dist: psycopg[binary]>=3.1; extra == "registry"
|
|
20
21
|
Dynamic: license-file
|
|
@@ -34,6 +34,7 @@ fd_open_data_protocol/vocabulary/relation_types.yaml
|
|
|
34
34
|
fd_open_data_protocol/vocabulary/units.yaml
|
|
35
35
|
fd_open_data_protocol/vocabulary/alignment/foundation.yaml
|
|
36
36
|
fd_open_data_protocol/vocabulary/crosswalks/datacommons-worldbank.yaml
|
|
37
|
+
tests/test_drift_inventory.py
|
|
37
38
|
tests/test_line_ops.py
|
|
38
39
|
tests/test_loader.py
|
|
39
40
|
tests/test_openalex_provider.py
|
|
@@ -19,7 +19,7 @@ dependencies = [
|
|
|
19
19
|
dev = ["pytest>=8.0", "pytest-asyncio>=0.23", "httpx>=0.27"]
|
|
20
20
|
# 线操作 MCP 的共享运行时(fd_open_data_protocol.line_ops.client)需要 httpx;
|
|
21
21
|
# auth_gate / config / wellknown 不需要。消费仓装上这个 extra 即可。
|
|
22
|
-
line-ops = ["httpx>=0.27"]
|
|
22
|
+
line-ops = ["httpx>=0.27", "starlette>=0.27"]
|
|
23
23
|
registry = ["psycopg[binary]>=3.1"]
|
|
24
24
|
|
|
25
25
|
[tool.pytest.ini_options]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Pure test for scripts/ontology_drift_inventory.py on fixture dirs (no DB)."""
|
|
2
|
+
|
|
3
|
+
import importlib.util
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
_SCRIPT = Path(__file__).resolve().parent.parent / "scripts" / "ontology_drift_inventory.py"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _load():
|
|
11
|
+
spec = importlib.util.spec_from_file_location("drift_inventory", _SCRIPT)
|
|
12
|
+
mod = importlib.util.module_from_spec(spec)
|
|
13
|
+
spec.loader.exec_module(mod)
|
|
14
|
+
return mod
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_drift_both_directions_and_null(tmp_path):
|
|
18
|
+
vocab = tmp_path / "vocab"
|
|
19
|
+
vocab.mkdir()
|
|
20
|
+
(vocab / "entity_types.yaml").write_text(
|
|
21
|
+
"entity_types:\n - id: organization\n - id: person\n", encoding="utf-8")
|
|
22
|
+
(vocab / "relation_types.yaml").write_text(
|
|
23
|
+
"relation_types:\n - id: owns\n", encoding="utf-8")
|
|
24
|
+
(vocab / "concepts.yaml").write_text(
|
|
25
|
+
"families:\n - id: wage\n", encoding="utf-8")
|
|
26
|
+
|
|
27
|
+
spiders = tmp_path / "spiders"
|
|
28
|
+
(spiders / "src_a").mkdir(parents=True)
|
|
29
|
+
(spiders / "src_a" / "manifest.yaml").write_text(
|
|
30
|
+
"entity_type: organization\nentity_type: ghost\nconcept: wage.monthly\n"
|
|
31
|
+
"relationships: []\n", encoding="utf-8")
|
|
32
|
+
(spiders / "src_b").mkdir()
|
|
33
|
+
(spiders / "src_b" / "manifest.yaml").write_text(
|
|
34
|
+
"entity_type: person\nconcept: ghost.code\n", encoding="utf-8")
|
|
35
|
+
|
|
36
|
+
out = tmp_path / "out"
|
|
37
|
+
mod = _load()
|
|
38
|
+
rc = mod.main(["--spiders-dir", str(spiders), "--vocab-dir", str(vocab), "--out", str(out)])
|
|
39
|
+
assert rc == 0
|
|
40
|
+
|
|
41
|
+
rep = json.loads((out / "drift.json").read_text(encoding="utf-8"))
|
|
42
|
+
s = rep["summary"]
|
|
43
|
+
assert s["entity_type_outside_vocab"] == 1 # ghost
|
|
44
|
+
assert [d["type"] for d in rep["entity_type_drift"]] == ["ghost"]
|
|
45
|
+
assert s["entity_type_never_used"] == 0 # organization/person both used
|
|
46
|
+
assert [d["code"] for d in rep["concept_drift"]] == ["ghost.code", "wage.monthly"]
|
|
47
|
+
assert s["concepts_outside_families"] == 2 # exact-id match: point codes are outside
|
|
48
|
+
# null relation declarations handled: only src_a declares a block
|
|
49
|
+
assert s["sources_with_relationships"] == 1
|
|
@@ -169,3 +169,72 @@ def test_assemble_accepts_gate_cls_and_manifest_anchor():
|
|
|
169
169
|
params = inspect.signature(assemble).parameters
|
|
170
170
|
assert "gate_cls" in params
|
|
171
171
|
assert "manifest_anchor" in params
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def test_register_mounts_the_endpoint_and_serves_the_manifest(tmp_path):
|
|
175
|
+
"""共享 register() 的 404/200 两态与缓存头,锚点决定仓根。"""
|
|
176
|
+
import asyncio
|
|
177
|
+
|
|
178
|
+
import pytest
|
|
179
|
+
|
|
180
|
+
pytest.importorskip("starlette.responses")
|
|
181
|
+
from fd_open_data_protocol.line_ops import wellknown
|
|
182
|
+
|
|
183
|
+
class FakeMCP:
|
|
184
|
+
def __init__(self):
|
|
185
|
+
self.handlers = {}
|
|
186
|
+
|
|
187
|
+
def custom_route(self, path, methods):
|
|
188
|
+
def deco(fn):
|
|
189
|
+
self.handlers[path] = fn
|
|
190
|
+
return fn
|
|
191
|
+
|
|
192
|
+
return deco
|
|
193
|
+
|
|
194
|
+
repo = tmp_path / "repo"
|
|
195
|
+
(repo / "pkg").mkdir(parents=True)
|
|
196
|
+
anchor = repo / "pkg" / "server.py"
|
|
197
|
+
anchor.write_text("")
|
|
198
|
+
app = FakeMCP()
|
|
199
|
+
wellknown.register(app, anchor=anchor)
|
|
200
|
+
handler = app.handlers[wellknown.WELL_KNOWN_PATH]
|
|
201
|
+
|
|
202
|
+
missing = asyncio.run(handler(None))
|
|
203
|
+
assert missing.status_code == 404
|
|
204
|
+
|
|
205
|
+
manifest = repo / "line-manifest.json"
|
|
206
|
+
manifest.write_text('{"line": "x"}')
|
|
207
|
+
ok = asyncio.run(handler(None))
|
|
208
|
+
assert ok.status_code == 200
|
|
209
|
+
assert ok.headers.get("cache-control") == wellknown.MANIFEST_CACHE_CONTROL
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def test_register_supports_a_fastapi_style_app(tmp_path):
|
|
213
|
+
"""paper-trading 是 FastAPI 单进程:register 必须走 app.get,而不是 custom_route。"""
|
|
214
|
+
import asyncio
|
|
215
|
+
|
|
216
|
+
import pytest
|
|
217
|
+
|
|
218
|
+
pytest.importorskip("starlette.responses")
|
|
219
|
+
from fd_open_data_protocol.line_ops import wellknown
|
|
220
|
+
|
|
221
|
+
class FakeApp:
|
|
222
|
+
def __init__(self):
|
|
223
|
+
self.routes = {}
|
|
224
|
+
|
|
225
|
+
def get(self, path, include_in_schema=True):
|
|
226
|
+
def deco(fn):
|
|
227
|
+
self.routes[path] = fn
|
|
228
|
+
return fn
|
|
229
|
+
|
|
230
|
+
return deco
|
|
231
|
+
|
|
232
|
+
repo = tmp_path / "repo"
|
|
233
|
+
(repo / "pkg").mkdir(parents=True)
|
|
234
|
+
anchor = repo / "pkg" / "server.py"
|
|
235
|
+
anchor.write_text("")
|
|
236
|
+
(repo / "line-manifest.json").write_text('{"line": "paper-trading"}')
|
|
237
|
+
app = FakeApp()
|
|
238
|
+
wellknown.register(app, anchor=anchor)
|
|
239
|
+
response = asyncio.run(app.routes[wellknown.WELL_KNOWN_PATH]())
|
|
240
|
+
assert response.status_code == 200
|
|
@@ -184,3 +184,17 @@ def test_seeded_variables_carry_family():
|
|
|
184
184
|
by_code = {(s.code, s.measure): s for s in v.seeded_variables()}
|
|
185
185
|
assert by_code[("gdp", "nominal_current")].family_id == "GDP"
|
|
186
186
|
assert by_code[("population.total", "")].family_id == "Population"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def test_relation_domain_range_must_name_known_entity_types(tmp_path):
|
|
190
|
+
"""A relation's source_types/target_types naming an unknown entity type is a typo, not intent."""
|
|
191
|
+
dst = tmp_path / "vocab"
|
|
192
|
+
shutil.copytree(SHIPPED, dst)
|
|
193
|
+
rt = dst / "relation_types.yaml"
|
|
194
|
+
data = yaml.safe_load(rt.read_text(encoding="utf-8"))
|
|
195
|
+
data["entries"][0]["target_types"] = list(data["entries"][0].get("target_types") or []) + [
|
|
196
|
+
"not_a_type"
|
|
197
|
+
]
|
|
198
|
+
rt.write_text(yaml.safe_dump(data, allow_unicode=True), encoding="utf-8")
|
|
199
|
+
errs = validate_vocabulary(dst)
|
|
200
|
+
assert any("not_a_type" in e and "unknown entity type" in e for e in errs), errs
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/tests/test_vocabulary_additive.py
RENAMED
|
@@ -63,12 +63,27 @@ def test_an_unchanged_release_is_additive(releases) -> None:
|
|
|
63
63
|
def test_removing_an_entry_fails_and_names_it(releases) -> None:
|
|
64
64
|
baseline, current = releases
|
|
65
65
|
entity_types = current / "entity_types.yaml"
|
|
66
|
+
relations = current / "relation_types.yaml"
|
|
67
|
+
removed: dict[str, str] = {}
|
|
66
68
|
|
|
67
69
|
def drop_first(data):
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
removed_id = data["entries"].pop(0)["id"]
|
|
71
|
+
removed["id"] = removed_id
|
|
72
|
+
data["_dropped"] = removed_id # carried only for the assertion below
|
|
70
73
|
|
|
71
74
|
_edit(entity_types, drop_first)
|
|
75
|
+
|
|
76
|
+
# Keep the release structurally valid so the ONLY error is non-additivity:
|
|
77
|
+
# a relation must not name an entity type that no longer exists (the
|
|
78
|
+
# referential-integrity check would otherwise fire first).
|
|
79
|
+
def prune_relation_refs(data):
|
|
80
|
+
rid = removed["id"]
|
|
81
|
+
for e in data["entries"]:
|
|
82
|
+
for key in ("source_types", "target_types"):
|
|
83
|
+
if e.get(key):
|
|
84
|
+
e[key] = [t for t in e[key] if t != rid]
|
|
85
|
+
|
|
86
|
+
_edit(relations, prune_relation_refs)
|
|
72
87
|
_bump_release(current)
|
|
73
88
|
dropped = yaml.safe_load(entity_types.read_text(encoding="utf-8"))["_dropped"]
|
|
74
89
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/client.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/line_ops/config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/provider.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/registry.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/registry_cli.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/registry_store.py
RENAMED
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.1 → fd_open_data_protocol-0.5.4}/fd_open_data_protocol/surface_report.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|