From 8b79a4dccd9953a5f1b427c5a3120420ef4a2acd Mon Sep 17 00:00:00 2001 From: bensynapse <118375461+bensynapse@users.noreply.github.com> Date: Wed, 25 Nov 2026 06:49:08 +0200 Subject: [PATCH] Add a version compatibility matrix to the client libraries page The page now maps every official library to its current release, the public API version it targets and its minimum runtime. The public API version is read from the default base URL each library ships. The build check compares it with the version the spec serves. A contents list at the top links every section, including the new one. The page now reports the later read date as its last modified date, so the sitemap and the article data stay honest about the change. New tests cover the matrix and the drift checks. --- docs/client-libraries.html | 41 ++++++- docs/llms.txt | 2 +- docs/sitemap.xml | 2 +- scripts/build_reference.py | 130 ++++++++++++++++++++- scripts/test_build_reference.py | 194 ++++++++++++++++++++++++++++++++ 5 files changed, 363 insertions(+), 6 deletions(-) create mode 100644 scripts/test_build_reference.py diff --git a/docs/client-libraries.html b/docs/client-libraries.html index 8c168db..5c56fa4 100644 --- a/docs/client-libraries.html +++ b/docs/client-libraries.html @@ -15,7 +15,7 @@ @@ -217,6 +217,18 @@

Live Tennis API client libraries

+

Which client library should I use?

Pick the row for your language. Every package calls the same REST API with the same key. The version is the newest release on the registry named under each install command. @@ -240,6 +252,33 @@

Which client library should I use?

Every package is MIT licensed. Plugins for apps and automation platforms are not in this table. They live in the GitHub organisation.

+

Which API version and runtime does each library target?

+

This matrix pins every official library to one row. Each row names the current release, the +public API version the library calls, and the lowest language or runtime version it supports.

+
+ + + + + + + + + + + + + + +
Each official library with its current release, the public API version it targets and its minimum runtime
LibraryCurrent releasePublic API versionMinimum runtime
Python client1.8.0v1Python 3.9
JavaScript and TypeScript client1.10.3v1Node 18
Go client1.3.0v1Go 1.25
PHP client1.2.0v1PHP 8.1
.NET client1.2.1v1.NET Standard 2.0 or .NET 8
Dart and Flutter client1.2.1v1Dart 3.5
Swift client1.2.1v1Swift 5.9
R client0.2.1v1R 4.1
MCP server1.6.5v1Node 20
Vercel AI SDK tools1.3.0v1Node 22
Export command0.1.0v1Python 3.9
Laravel package1.1.0v1PHP 8.2
Haystack integration0.2.0v1Python 3.10
LangChain integration0.2.0v1Python 3.10
LlamaIndex tools0.1.0v1Python 3.10
+

Every library here targets the same public API version, so moving between libraries needs no +change of API version. The build check compares each stated version with the version the spec serves +and fails if they differ.

+

The current release and minimum runtime were read from each library's registry, or its Git tags +where it has none, on . The public API +version is the one in each library's default base URL, or in the client it wraps, read from source +on .

+

Which libraries support REST, the live stream, file export and MCP?

Every library reads the REST API. Two open the live stream, one writes files and one is an MCP server.

diff --git a/docs/llms.txt b/docs/llms.txt index 10447ad..67331cc 100644 --- a/docs/llms.txt +++ b/docs/llms.txt @@ -256,7 +256,7 @@ backtest. - Haystack integration: `pip install livetennisapi-haystack`, package https://pypi.org/project/livetennisapi-haystack/, source https://github.com/livetennisapi/livetennisapi-haystack - LangChain integration: `pip install -U langchain-livetennis`, package https://pypi.org/project/langchain-livetennis/, source https://github.com/livetennisapi/langchain-livetennis - LlamaIndex tools: `pip install llama-index-tools-livetennisapi`, package https://pypi.org/project/llama-index-tools-livetennisapi/, source https://github.com/livetennisapi/llama-index-tools-livetennisapi -- Every library with its latest version, minimum runtime and endpoint coverage: https://docs.livetennisapi.com/client-libraries.html +- Every library with its current release, the public API version it targets, its minimum runtime and endpoint coverage: https://docs.livetennisapi.com/client-libraries.html ## Affiliate programme - https://affiliates.livetennisapi.com/program — 51% recurring commission for the lifetime diff --git a/docs/sitemap.xml b/docs/sitemap.xml index b925e09..3f73719 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -14,7 +14,7 @@ https://docs.livetennisapi.com/ai-sdk.html2026-10-22weekly0.8https://docs.livetennisapi.com/errors-and-rate-limits.html2026-11-09weekly0.8https://docs.livetennisapi.com/export-formats.html2026-11-11weekly0.8 - https://docs.livetennisapi.com/client-libraries.html2026-11-19weekly0.8 + https://docs.livetennisapi.com/client-libraries.html2026-11-25weekly0.8https://docs.livetennisapi.com/sportsml.html2026-11-15weekly0.8https://docs.livetennisapi.com/changelog.html2026-11-21weekly0.6 diff --git a/scripts/build_reference.py b/scripts/build_reference.py index 0aad291..2bb523f 100644 --- a/scripts/build_reference.py +++ b/scripts/build_reference.py @@ -1392,7 +1392,7 @@ def build_llms_txt(spec: dict[str, Any]) -> str: " fixtures, players, player, rankings and tournaments. Reads the key from LIVETENNISAPI_KEY.", *[f"- {c['name']}: `{c['install']}`, package {c['registry_url']}, source {c['repo']}" for c in CLIENTS if c["key"] in CLIENTS_LLMS_EXTRA], - f"- Every library with its latest version, minimum runtime and endpoint coverage: {DOCS_URL}/client-libraries.html", + f"- Every library with its current release, the public API version it targets, its minimum runtime and endpoint coverage: {DOCS_URL}/client-libraries.html", "", "## Affiliate programme", "- https://affiliates.livetennisapi.com/program — 51% recurring commission for the lifetime", @@ -3420,6 +3420,32 @@ def _export_body(spec: dict[str, Any]) -> str: # Every listed package states the MIT licence on its registry or, for Swift, in its LICENSE file. CLIENTS_LICENCE = "MIT" +# The public API version each library targets, for the version compatibility matrix. The value is +# the path segment after /api/public/ in the default base URL the library ships. It was read from +# each library's own source on API_VERSION_CHECKED, one source per key: +# python src/livetennisapi/_base.py DEFAULT_BASE_URL +# js src/client.ts DEFAULT_BASE_URL +# go README.md quick start WithBaseURL(...) +# php src/LiveTennisApi.php DEFAULT_BASE_URL +# dotnet src/LiveTennisApi/LiveTennisApiClientOptions.cs DefaultBaseUrl +# dart lib/src/client.dart defaultBaseUrl +# swift Sources/LiveTennisApi/LiveTennisApiClient.swift defaultBaseURL +# r R/client.R lta_base_url() +# langchain langchain_livetennis/_client.py the shipped base URL +# llamaindex llama_index/tools/livetennisapi/base.py the shipped base URL +# laravel config/livetennis.php the shipped base URL +# The remaining packages call the API through a language client and so target that client's version: +# mcp and ai through the JavaScript client, export and haystack through the Python client. +# A value is "not stated" when a library's source names no base URL. None do today. The build check +# in _clients_drift compares every value here with the version the spec serves, so a row cannot +# quietly target a version the API no longer publishes. +API_VERSION_CHECKED = "2026-11-25" +CLIENT_API_VERSION: dict[str, str] = { + "python": "v1", "js": "v1", "go": "v1", "php": "v1", "dotnet": "v1", "dart": "v1", + "swift": "v1", "r": "v1", "mcp": "v1", "ai": "v1", "export": "v1", "laravel": "v1", + "haystack": "v1", "langchain": "v1", "llamaindex": "v1", +} + # The eight language clients, in the column order of the endpoint table. CLIENT_LANGUAGES = ["python", "js", "go", "php", "dotnet", "dart", "swift", "r"] CLIENT_SHORT = {"python": "Python", "js": 'JS', "go": "Go", "php": "PHP", "dotnet": ".NET", @@ -3642,6 +3668,37 @@ def _samples_match_clients_page() -> list[str]: return problems +def _spec_api_version(spec: dict[str, Any]) -> str: + """The public API version the spec serves, read from the last path segment of its server URL. + + The server is ``https://api.livetennisapi.com/api/public/v1``, so this returns ``v1``. The + compatibility matrix compares every library's targeted version against this, so the version is + never typed twice: it is read from the spec that the SDKs are generated from. + """ + # Read every server the spec declares, not only the top-level list: OpenAPI lets a path item + # or an operation override the server, and a staged v2 override there must not hide behind the + # top-level v1. Collect them all and require one version, so the matrix cannot drift from any + # server the API actually publishes. + def server_urls(node: Any) -> list[str]: + if not isinstance(node, dict): + return [] + return [s["url"] for s in (node.get("servers") or []) if isinstance(s, dict) and "url" in s] + + urls = server_urls(spec) + for path_item in (spec.get("paths") or {}).values(): + urls += server_urls(path_item) + if isinstance(path_item, dict): + for operation in path_item.values(): + urls += server_urls(operation) + if not urls: + raise SystemExit("the spec declares no server, so the public API version is unknown") + versions = {url.rstrip("/").rsplit("/", 1)[-1] for url in urls} + if len(versions) != 1: + raise SystemExit("the spec serves more than one public API version: " + + ", ".join(sorted(versions))) + return versions.pop() + + def _clients_drift(spec: dict[str, Any]) -> None: """Fail the build when the page names an operation the spec no longer has, or a row is malformed.""" problems = [] @@ -3679,6 +3736,23 @@ def _clients_drift(spec: dict[str, Any]) -> None: problems.append("the Swift install line does not name the Swift row's version") if "get" not in spec["paths"].get("/ws-token", {}): problems.append("the page explains Token only with GET /ws-token, which the spec does not define") + # The version compatibility matrix. Its release-line cell is each row's own version, the same + # field the install matrix shows, so the two tables cannot name different versions for a + # library. For the eight language clients that version is also pinned against + # code-samples/sdk-methods.yaml by _samples_match_clients_page. Its API-version cell must match + # the version the spec serves, so the matrix cannot keep naming v1 after the API moves on. + spec_api_version = _spec_api_version(spec) + for key in keys: + if key not in CLIENT_API_VERSION: + problems.append(f"the compatibility matrix has no public API version for the row {key!r}") + for key in CLIENT_API_VERSION: + if key not in by_key: + problems.append(f"CLIENT_API_VERSION names {key!r}, which is not a library row") + for key, api_version in CLIENT_API_VERSION.items(): + if api_version != "not stated" and api_version != spec_api_version: + problems.append( + f"the compatibility matrix says {key} targets API {api_version}, " + f"but the spec serves {spec_api_version}") if problems: raise SystemExit("client-libraries.html disagrees with the spec or itself:\n " + "\n ".join(problems)) @@ -3718,6 +3792,26 @@ def install_cell(c: dict[str, Any]) -> str: "" + rows + "
Which parts of the API each library covers
LibraryRESTLive streamFile exportMCP
Python clientYesYesNoNo
", "Client libraries", ) + # The version compatibility matrix: one row per library, its current release, the public API + # version it targets and its minimum runtime. The API-version cell is read from CLIENT_API_VERSION + # and shown as "Not stated" where a library's source names no base URL (none do today). + def api_version_cell(key: str) -> str: + value = CLIENT_API_VERSION.get(key, "not stated") + return "Not stated" if value == "not stated" else value + + compat_rows = "".join( + f'{E(c["name"])}' + f'{E(c["version"])}{E(api_version_cell(c["key"]))}' + f'{E(c["runtime"])}\n' + for c in CLIENTS + ) + compat = scrollx( + f"{vh_caption('Each official library with its current release, the public API version it targets and its minimum runtime')}" + '' + '' + "" + compat_rows + "
LibraryCurrent releasePublic API versionMinimum runtime
", + "Version compatibility", + ) cover_rows = "".join( f'{E(c["name"])}Yes{E(c["stream"])}' f'{E(c["export"])}{E(c["mcp"])}\n' @@ -3757,7 +3851,7 @@ def install_cell(c: dict[str, Any]) -> str: + (f"

{CLIENT_QUICKSTART_AFTER[key]}

\n" if key in CLIENT_QUICKSTART_AFTER else "") for key, heading, install, snippet, note in CLIENT_QUICKSTARTS ) - return f"""

Which client library should I use?

+ body = f"""

Which client library should I use?

Pick the row for your language. Every package calls the same REST API with the same key. The version is the newest release on the registry named under each install command. These client libraries are the official SDKs for the API.

@@ -3765,6 +3859,18 @@ def install_cell(c: dict[str, Any]) -> str:

Every package is MIT licensed. Plugins for apps and automation platforms are not in this table. They live in the GitHub organisation.

+

Which API version and runtime does each library target?

+

This matrix pins every official library to one row. Each row names the current release, the +public API version the library calls, and the lowest language or runtime version it supports.

+{compat} +

Every library here targets the same public API version, so moving between libraries needs no +change of API version. The build check compares each stated version with the version the spec serves +and fails if they differ.

+

The current release and minimum runtime were read from each library's registry, or its Git tags +where it has none, on . The public API +version is the one in each library's default base URL, or in the client it wraps, read from source +on .

+

Which libraries support REST, the live stream, file export and MCP?

Every library reads the REST API. Two open the live stream, one writes files and one is an MCP server.

{coverage} @@ -3807,6 +3913,21 @@ def install_cell(c: dict[str, Any]) -> str: for spreadsheets, with no package to install """ + # The contents list is generated from the section headings, so a new section appears in it + # without a second edit and the list can never name a section the page does not have. + headings = re.findall(r'

(.*?)

', body) + # Guard: every section heading must reach the list. A heading written with another attribute + # before id, or wrapped across lines, would slip past the strict pattern and vanish from the + # nav. Count every

]", body)): + raise SystemExit("the client libraries contents list missed a section heading: " + "every

must open with its id attribute on one line") + items = "".join(f'
  • {text}
  • \n' for sid, text in headings) + contents = ('\n") + return contents + body # ----------------------------------------------------------------- SportsML mapping ------------- @@ -4290,7 +4411,10 @@ def _sportsml_body(spec: dict[str, Any]) -> str: "Coverage read from the source of each published version." ), "body": _clients_body, - "date": CLIENTS_CHECKED, + # dateModified and the sitemap lastmod track the page's newest content check. The version + # compatibility matrix was read on API_VERSION_CHECKED, later than CLIENTS_CHECKED, so the + # page changed that day. The registry read date stays CLIENTS_CHECKED in the meta and prose. + "date": max(CLIENTS_CHECKED, API_VERSION_CHECKED), "about": [ {"@type": "SoftwareSourceCode", "name": f'Live Tennis API {c["name"]}', "alternateName": c["package"], "url": c["registry_url"], "version": c["version"], diff --git a/scripts/test_build_reference.py b/scripts/test_build_reference.py new file mode 100644 index 0000000..69d612b --- /dev/null +++ b/scripts/test_build_reference.py @@ -0,0 +1,194 @@ +"""Tests for the client libraries version compatibility matrix. + +Run: python -m unittest scripts/test_build_reference.py + +The first group checks the committed client-libraries.html: the compatibility section and its +anchor exist, the contents list links it, and every library row names its current release, the +public API version it targets and its minimum runtime. The release line is each library's own +version, and the API version is the one the spec serves, so the second group breaks copies of +those inputs and checks that the build refuses each one. The real files are never written. +""" + +from __future__ import annotations + +import copy +import re +import sys +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import build_reference as br # noqa: E402 + +PAGE = br.DOCS / "client-libraries.html" + + +def a_different_version(version: str) -> str: + """A public API version that is not the current one, for the drift tests. + + Derived from the current version so these tests still exercise a real mismatch after a future + migration (v1 to v2 and so on), rather than hard-coding the next version. + """ + match = re.fullmatch(r"v(\d+)", version) + return f"v{int(match.group(1)) + 1}" if match else version + "x" + + +def compat_table(html: str) -> str: + """The rendered compatibility table block.""" + match = re.search(r'aria-label="Version compatibility".*?', html, re.S) + assert match, "the compatibility table is not on the page" + return match.group(0) + + +def compat_rows(html: str) -> list[list[str]]: + rows = [] + for row in re.findall(r"(.*?)", compat_table(html), re.S)[1:]: + cells = [re.sub(r"<[^>]+>", "", c).strip() + for c in re.findall(r"]*>(.*?)", row, re.S)] + rows.append(cells) + return rows + + +class CommittedPageTest(unittest.TestCase): + """Assertions against the generated file as it is committed.""" + + @classmethod + def setUpClass(cls) -> None: + cls.html = PAGE.read_text(encoding="utf-8") + cls.spec = br.load_spec() + + def test_section_and_anchor_present(self) -> None: + self.assertIn('id="compatibility"', self.html) + self.assertIn("Which API version and runtime does each library target?", self.html) + self.assertEqual(self.html.count('id="compatibility"'), 1) + + def test_contents_links_the_section(self) -> None: + nav = re.search(r'aria-labelledby="contents-heading".*?', self.html, re.S) + self.assertIsNotNone(nav, "no contents nav on the page") + self.assertIn('', nav.group(0)) + + def test_every_in_page_link_in_contents_resolves(self) -> None: + nav = re.search(r'aria-labelledby="contents-heading".*?', self.html, re.S).group(0) + for anchor in re.findall(r'href="#([^"]+)"', nav): + self.assertIn(f'id="{anchor}"', self.html, f"contents links #{anchor}, which has no target") + + def test_every_library_has_a_row_with_release_api_and_runtime(self) -> None: + rows = compat_rows(self.html) + self.assertEqual(len(rows), len(br.CLIENTS)) + by_name = {r[0]: r for r in rows} + spec_api = br._spec_api_version(self.spec) + for client in br.CLIENTS: + with self.subTest(client=client["key"]): + row = by_name[client["name"]] + # Library, current release, public API version, minimum runtime. + self.assertEqual(row[1], client["version"]) + want = br.CLIENT_API_VERSION[client["key"]] + shown = "Not stated" if want == "not stated" else want + self.assertEqual(row[2], shown) + if want != "not stated": + self.assertEqual(row[2], spec_api) + self.assertEqual(row[3], client["runtime"]) + + def test_release_line_matches_the_sdk_version(self) -> None: + # The matrix must not name a release line that differs from the library's own version, the + # same version the install table and code-samples pin. This is the stated-version guard. + versions = {r[0]: r[1] for r in compat_rows(self.html)} + for client in br.CLIENTS: + self.assertEqual(versions[client["name"]], client["version"]) + + def test_spec_api_version_reads_from_the_server(self) -> None: + self.assertEqual(br._spec_api_version(self.spec), "v1") + + def test_spec_api_version_requires_a_server(self) -> None: + with self.assertRaises(SystemExit): + br._spec_api_version({"servers": []}) + + def test_spec_api_version_rejects_disagreeing_servers(self) -> None: + with self.assertRaises(SystemExit): + br._spec_api_version({"servers": [ + {"url": "https://sandbox.livetennisapi.com/api/public/v1"}, + {"url": "https://api.livetennisapi.com/api/public/v2"}, + ]}) + + def test_committed_body_matches_the_generator(self) -> None: + # The whole generated body, prose and tables and contents, must appear verbatim in the + # committed page. A hand-edit to any of it, not only a matrix cell, is then caught here as + # well as by `build_reference.py --check`. + self.assertIn(br._clients_body(self.spec), self.html) + + def test_release_line_matches_the_code_sample_versions(self) -> None: + # The release line is pinned to an independent statement of each client's version, so this + # is not circular: code-samples/sdk-methods.yaml is read from a separate file. This is the + # build-time guard for "the matrix matches an SDK's stated version" for the language clients. + methods = br.build_code_samples.load_methods() + cells = {r[0]: r[1] for r in compat_rows(self.html)} + by_key = {c["key"]: c for c in br.CLIENTS} + for key in br.CLIENT_LANGUAGES: + with self.subTest(client=key): + stated = str(methods["clients"][key]["version"]) + self.assertEqual(cells[by_key[key]["name"]], stated) + + def test_baseline_does_not_raise(self) -> None: + br._clients_drift(self.spec) + + +class DriftTest(unittest.TestCase): + """Breaking an input must fail the build.""" + + def setUp(self) -> None: + self.spec = br.load_spec() + self._saved = dict(br.CLIENT_API_VERSION) + + def tearDown(self) -> None: + br.CLIENT_API_VERSION.clear() + br.CLIENT_API_VERSION.update(self._saved) + + def test_fails_when_a_row_targets_another_api_version(self) -> None: + other = a_different_version(br._spec_api_version(self.spec)) + br.CLIENT_API_VERSION["python"] = other + with self.assertRaises(SystemExit) as caught: + br._clients_drift(self.spec) + self.assertIn(f"targets API {other}", str(caught.exception)) + + def test_fails_when_the_spec_moves_to_a_new_version(self) -> None: + other = a_different_version(br._spec_api_version(self.spec)) + spec = copy.deepcopy(self.spec) + spec["servers"][0]["url"] = f"https://api.livetennisapi.com/api/public/{other}" + with self.assertRaises(SystemExit) as caught: + br._clients_drift(spec) + self.assertIn(f"spec serves {other}", str(caught.exception)) + + def test_fails_when_a_row_has_no_api_version(self) -> None: + br.CLIENT_API_VERSION.pop("swift") + with self.assertRaises(SystemExit) as caught: + br._clients_drift(self.spec) + self.assertIn("swift", str(caught.exception)) + self.assertIn("no public API version", str(caught.exception)) + + def test_fails_when_api_version_names_an_unknown_row(self) -> None: + # Give the orphan the current version so a version mismatch cannot mask the orphan check: + # only the orphan check can make this fail, whatever the current API version is. + br.CLIENT_API_VERSION["ghost"] = br._spec_api_version(self.spec) + with self.assertRaises(SystemExit) as caught: + br._clients_drift(self.spec) + self.assertIn("ghost", str(caught.exception)) + + def test_body_builder_runs_the_drift_check(self) -> None: + # The guard is only useful if the page builder actually calls it. Break a row and confirm + # that building the body (not just calling _clients_drift directly) fails. + br.CLIENT_API_VERSION["python"] = a_different_version(br._spec_api_version(self.spec)) + with self.assertRaises(SystemExit): + br._clients_body(self.spec) + + def test_not_stated_is_rendered_and_skipped(self) -> None: + # A library with no stated base URL shows "Not stated" and is not compared with the spec + # version. None do today, so this exercises that otherwise dead branch. + br.CLIENT_API_VERSION["r"] = "not stated" + br._clients_drift(self.spec) # must not raise: "not stated" is skipped + r_row = next(row for row in compat_rows(br._clients_body(self.spec)) + if row[0] == "R client") + self.assertEqual(r_row[2], "Not stated") + + +if __name__ == "__main__": + unittest.main()