fd-open-data-protocol 0.5.0__tar.gz → 0.5.3__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.0 → fd_open_data_protocol-0.5.3}/PKG-INFO +2 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/__init__.py +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/__init__.py +2 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/assemble.py +11 -2
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/client.py +7 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/wellknown.py +41 -6
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/concepts.yaml +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/crosswalks/datacommons-worldbank.yaml +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/entity_types.yaml +114 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/event_types.yaml +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/qualifiers.yaml +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/relation_types.yaml +1 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/units.yaml +11 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary.py +30 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol.egg-info/PKG-INFO +2 -1
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol.egg-info/SOURCES.txt +1 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol.egg-info/requires.txt +1 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/pyproject.toml +1 -1
- fd_open_data_protocol-0.5.3/tests/test_drift_inventory.py +49 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_line_ops.py +77 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_vocabulary.py +14 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_vocabulary_additive.py +17 -2
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/LICENSE +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/README.md +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/conformance_adapter.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/constants.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/auth_gate.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/config.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/loader.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/openalex_provider.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/provider.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/registry.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/registry_cli.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/registry_store.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/schema.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/surface_report.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/surface_selfcheck.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/vocabulary/alignment/foundation.yaml +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol.egg-info/dependency_links.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol.egg-info/entry_points.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol.egg-info/top_level.txt +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/setup.cfg +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_loader.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_openalex_provider.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_registry_pipeline.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_registry_schema.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_schema_vocabulary.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/tests/test_surface_report.py +0 -0
- {fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/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.3
|
|
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
|
]
|
|
@@ -22,6 +22,8 @@ def assemble(
|
|
|
22
22
|
auth_cache_ttl_seconds: float = 60.0,
|
|
23
23
|
mcp_path: str = "/mcp",
|
|
24
24
|
enable_surface_report: bool = True,
|
|
25
|
+
gate_cls: Callable[[Any, AuthGate], Any] | None = None,
|
|
26
|
+
manifest_anchor: str | None = None,
|
|
25
27
|
):
|
|
26
28
|
"""返回完整 ASGI app:/health 与线自描述免门,其余走鉴权门(无 Bearer 拒)。
|
|
27
29
|
|
|
@@ -30,12 +32,19 @@ def assemble(
|
|
|
30
32
|
:param mcp_path: MCP 端点路径
|
|
31
33
|
:param enable_surface_report: 是否在首请求触发 `surface_report.ensure_started`。
|
|
32
34
|
该机制要求服务对象带 `_surface_report` 属性;本模块会初始化它。
|
|
35
|
+
:param gate_cls: 鉴权门中间件类,签名 `(app, gate)`。默认用共享实现;
|
|
36
|
+
消费仓传入自己 re-export 的那个名字,使测试 `monkeypatch.setattr(server,
|
|
37
|
+
"AuthGateMiddleware", …)` 能真的替换掉本函数里用的类。
|
|
38
|
+
:param manifest_anchor: 用来定位消费仓 `line-manifest.json` 的文件路径。
|
|
39
|
+
**消费仓必须传自己的**(通常 `__file__`):不传就按 protocol 包的
|
|
40
|
+
位置推导,仓根会算错(见 `wellknown.manifest_candidates`)。
|
|
33
41
|
"""
|
|
34
42
|
mcp = build_mcp()
|
|
35
43
|
if enable_surface_report and not hasattr(mcp, "_surface_report"):
|
|
36
44
|
mcp._surface_report = "not_configured"
|
|
37
45
|
mcp_app = mcp.http_app(path=mcp_path)
|
|
38
|
-
|
|
46
|
+
_gate_cls = gate_cls or AuthGateMiddleware
|
|
47
|
+
gate = _gate_cls(mcp_app, AuthGate(auth_cache_ttl_seconds))
|
|
39
48
|
|
|
40
49
|
if enable_surface_report:
|
|
41
50
|
from fd_open_data_protocol import surface_report as _sr
|
|
@@ -61,7 +70,7 @@ def assemble(
|
|
|
61
70
|
# 线自描述:公开元数据,必须在鉴权门**之前**应答(与 /health 同理),
|
|
62
71
|
# 否则平台/客户在未持有本线凭据时连「这条线认哪些钥匙」都读不到。
|
|
63
72
|
if path == WELL_KNOWN_PATH.rstrip("/"):
|
|
64
|
-
status, body, headers = manifest_response()
|
|
73
|
+
status, body, headers = manifest_response(manifest_anchor)
|
|
65
74
|
await send({"type": "http.response.start", "status": status,
|
|
66
75
|
"headers": headers + [(b"content-length", str(len(body)).encode())]})
|
|
67
76
|
await send({"type": "http.response.body", "body": body})
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/client.py
RENAMED
|
@@ -83,6 +83,11 @@ class LineClient:
|
|
|
83
83
|
raise self._error(
|
|
84
84
|
"unreachable", None, f"{self._label}服务不可达:{type(e).__name__}: {e}"
|
|
85
85
|
) from e
|
|
86
|
+
return self._resolve(res)
|
|
87
|
+
|
|
88
|
+
def _resolve(self, res) -> Any:
|
|
89
|
+
"""状态码 → 值或错误。子类扩额外端点(如 multipart 上传)时复用它,
|
|
90
|
+
免得把这张映射表复制一遍(复制必然漂移)。"""
|
|
86
91
|
if res.status_code == 401:
|
|
87
92
|
raise self._error("unauthorized", 401, _detail(res))
|
|
88
93
|
if res.status_code == 402:
|
|
@@ -98,7 +103,8 @@ class LineClient:
|
|
|
98
103
|
if res.status_code == 429:
|
|
99
104
|
raise self._error("rate_limited", 429, _detail(res))
|
|
100
105
|
if res.status_code >= 500:
|
|
101
|
-
raise self._error("unreachable", res.status_code,
|
|
106
|
+
raise self._error("unreachable", res.status_code,
|
|
107
|
+
f"{self._label}服务错误:{_detail(res)}")
|
|
102
108
|
if res.status_code >= 400:
|
|
103
109
|
raise self._error("invalid", res.status_code, _detail(res))
|
|
104
110
|
if not res.content:
|
|
@@ -15,18 +15,23 @@ LINE_MANIFEST_ENV = "LINE_MANIFEST_PATH"
|
|
|
15
15
|
MANIFEST_CACHE_CONTROL = "public, max-age=300"
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def manifest_candidates() -> list[Path]:
|
|
18
|
+
def manifest_candidates(anchor: Path | str | None = None) -> list[Path]:
|
|
19
19
|
"""按优先级列出可能放清单的位置(`LINE_MANIFEST_PATH` 一项即封顶)。
|
|
20
20
|
|
|
21
21
|
为什么要链而不是一条:**pip 装进去的包与源码树的 `__file__` 不同**。镜像是
|
|
22
22
|
console script 起的,`__file__` 落在 site-packages,`parents[1]` 根本不是仓根——
|
|
23
23
|
清单就在 `/app/line-manifest.json` 却读不到(lex 线 2026-11-11 真机 404,
|
|
24
24
|
源码运行验不出来)。所以源码树、CWD(镜像 WORKDIR)、与包同级三处依次找。
|
|
25
|
+
|
|
26
|
+
:param anchor: 用来推导「仓根」的文件路径。**消费仓必须传自己的**
|
|
27
|
+
(通常是该仓 `server.py` 的 `__file__`):不传就用本模块的 `__file__`,
|
|
28
|
+
那会指向 protocol 包自己的目录,算出来的仓根是错的(2026-11-25 实测:
|
|
29
|
+
五个消费仓的 `manifest_path()` 全部指到 protocol 包里)。
|
|
25
30
|
"""
|
|
26
31
|
override = os.environ.get(LINE_MANIFEST_ENV)
|
|
27
32
|
if override:
|
|
28
33
|
return [Path(override)]
|
|
29
|
-
here = Path(__file__).resolve()
|
|
34
|
+
here = Path(anchor).resolve() if anchor is not None else Path(__file__).resolve()
|
|
30
35
|
return [
|
|
31
36
|
here.parents[1] / "line-manifest.json", # 源码树 / 镜像里包与清单同根
|
|
32
37
|
Path.cwd() / "line-manifest.json", # pip 装的包:CWD 才是仓根
|
|
@@ -34,23 +39,23 @@ def manifest_candidates() -> list[Path]:
|
|
|
34
39
|
]
|
|
35
40
|
|
|
36
41
|
|
|
37
|
-
def manifest_path() -> Path:
|
|
42
|
+
def manifest_path(anchor: Path | str | None = None) -> Path:
|
|
38
43
|
"""实际取用的清单路径;都不存在时返回首选位置(让 404 能点名期望路径)。"""
|
|
39
|
-
candidates = manifest_candidates()
|
|
44
|
+
candidates = manifest_candidates(anchor)
|
|
40
45
|
for candidate in candidates:
|
|
41
46
|
if candidate.exists():
|
|
42
47
|
return candidate
|
|
43
48
|
return candidates[0]
|
|
44
49
|
|
|
45
50
|
|
|
46
|
-
def manifest_response() -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
|
|
51
|
+
def manifest_response(anchor: Path | str | None = None) -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
|
|
47
52
|
"""(status, body, extra_headers) —— 不读网络、不建会话。
|
|
48
53
|
|
|
49
54
|
缺失=404(该线未发布清单,属配置事实);存在但不可解析=500(属缺陷,不能
|
|
50
55
|
伪装成 404 让调用方以为「本来就没有」)。
|
|
51
56
|
"""
|
|
52
57
|
json_headers = [(b"content-type", b"application/json; charset=utf-8")]
|
|
53
|
-
path = manifest_path()
|
|
58
|
+
path = manifest_path(anchor)
|
|
54
59
|
try:
|
|
55
60
|
raw = path.read_bytes()
|
|
56
61
|
except FileNotFoundError:
|
|
@@ -65,3 +70,33 @@ def manifest_response() -> tuple[int, bytes, list[tuple[bytes, bytes]]]:
|
|
|
65
70
|
return 200, raw, json_headers + [
|
|
66
71
|
(b"cache-control", MANIFEST_CACHE_CONTROL.encode()),
|
|
67
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
|
+
if not hasattr(mcp, "custom_route"): # pragma: no cover - dependency error
|
|
88
|
+
raise RuntimeError(
|
|
89
|
+
"fastmcp 缺 custom_route:无法挂 " + WELL_KNOWN_PATH + "(升级依赖,别静默跳过)"
|
|
90
|
+
)
|
|
91
|
+
@mcp.custom_route(WELL_KNOWN_PATH, methods=["GET"])
|
|
92
|
+
async def line_manifest(_request): # noqa: ANN001 - ASGI boundary
|
|
93
|
+
from starlette.responses import Response # only the HTTP branch needs it
|
|
94
|
+
|
|
95
|
+
status, body, extra = manifest_response(anchor)
|
|
96
|
+
headers = {k.decode(): v.decode() for k, v in extra}
|
|
97
|
+
return Response(
|
|
98
|
+
content=body,
|
|
99
|
+
status_code=status,
|
|
100
|
+
media_type="application/json; charset=utf-8",
|
|
101
|
+
headers=headers,
|
|
102
|
+
)
|
|
@@ -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.0 → fd_open_data_protocol-0.5.3}/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.0 → fd_open_data_protocol-0.5.3}/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.3
|
|
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
|
|
@@ -130,3 +130,80 @@ def test_two_lines_dont_share_env():
|
|
|
130
130
|
L = make_settings_class("LEX_OPS", "https://lex.example")
|
|
131
131
|
assert W.from_env({"LEX_OPS_BASE_URL": "https://lex.example"}).base_url == "https://wire.example"
|
|
132
132
|
assert L.from_env({"WIRE_OPS_BASE_URL": "https://wire.example"}).base_url == "https://lex.example"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# ── wellknown 的 anchor ───────────────────────────────────────────────────
|
|
136
|
+
|
|
137
|
+
def test_manifest_candidates_anchor_controls_repo_root(tmp_path):
|
|
138
|
+
"""anchor 决定仓根:传消费仓的 server.py,清单路径就在那个仓里。
|
|
139
|
+
|
|
140
|
+
这个参数是本模块的**必要**接口而不是可选装饰:不传 anchor 时用 protocol 包自己的
|
|
141
|
+
`__file__` 推仓根,会把五个消费仓的清单指到 fd_open_data_protocol/ 下(2026-11-25
|
|
142
|
+
在 lex-ops 的 CI 上实测:manifest_path() 返回 protocol 包里的路径)。
|
|
143
|
+
"""
|
|
144
|
+
from fd_open_data_protocol.line_ops.wellknown import manifest_candidates
|
|
145
|
+
|
|
146
|
+
fake_repo = tmp_path / "wire_ops_mcp"
|
|
147
|
+
fake_repo.mkdir()
|
|
148
|
+
anchor = fake_repo / "server.py"
|
|
149
|
+
anchor.write_text("")
|
|
150
|
+
cands = manifest_candidates(anchor)
|
|
151
|
+
assert cands[0] == fake_repo.parent / "line-manifest.json", cands
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_manifest_path_env_override_wins(tmp_path, monkeypatch):
|
|
155
|
+
from fd_open_data_protocol.line_ops.wellknown import LINE_MANIFEST_ENV, manifest_path
|
|
156
|
+
|
|
157
|
+
target = tmp_path / "explicit.json"
|
|
158
|
+
target.write_text("{}")
|
|
159
|
+
monkeypatch.setenv(LINE_MANIFEST_ENV, str(target))
|
|
160
|
+
assert manifest_path() == target
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def test_assemble_accepts_gate_cls_and_manifest_anchor():
|
|
164
|
+
"""assemble 的参数是消费仓的契约:gate_cls 让测试能替换门,manifest_anchor 定仓根。"""
|
|
165
|
+
import inspect
|
|
166
|
+
|
|
167
|
+
from fd_open_data_protocol.line_ops import assemble
|
|
168
|
+
|
|
169
|
+
params = inspect.signature(assemble).parameters
|
|
170
|
+
assert "gate_cls" in params
|
|
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
|
|
@@ -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.0 → fd_open_data_protocol-0.5.3}/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.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/line_ops/config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/provider.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/registry.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/registry_cli.py
RENAMED
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/fd_open_data_protocol/registry_store.py
RENAMED
|
File without changes
|
|
File without changes
|
{fd_open_data_protocol-0.5.0 → fd_open_data_protocol-0.5.3}/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
|