From f80d00e206e5f4f3cfa615fc2e7989466c4f5e57 Mon Sep 17 00:00:00 2001 From: BenSmithGreyGroup Date: Tue, 2 Jun 2026 15:26:51 +0100 Subject: [PATCH 1/2] changed header to camel-case to match with user agents accepted on the datalab side --- src/datalab_api/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datalab_api/_base.py b/src/datalab_api/_base.py index b146986..9df17c5 100644 --- a/src/datalab_api/_base.py +++ b/src/datalab_api/_base.py @@ -85,7 +85,7 @@ def __init__(self, datalab_api_url: str, log_level: str = "WARNING"): self.log = logging.getLogger(__name__) self._http_client = httpx.Client - self._headers = {"User-Agent": f"Datalab Python API/{__version__}"} + self._headers = {"User-Agent": f"datalab-python-api/{__version__}"} self._detect_api_url() From fc310471c0a6743ec30449644c9fc2b4bb01af39 Mon Sep 17 00:00:00 2001 From: BenSmithGreyGroup Date: Tue, 2 Jun 2026 15:50:04 +0100 Subject: [PATCH 2/2] validate that the api client header matches known user agents of the datalab version. Raises a warning if not --- src/datalab_api/_base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/datalab_api/_base.py b/src/datalab_api/_base.py index 9df17c5..0ba0d18 100644 --- a/src/datalab_api/_base.py +++ b/src/datalab_api/_base.py @@ -99,6 +99,21 @@ def __init__(self, datalab_api_url: str, log_level: str = "WARNING"): ) self._find_api_key() + self._validate_user_agent() + + def _validate_user_agent(self) -> None: + """Warn if this client's User-Agent is not in the server's known agent list.""" + known_agents = self.info.get("attributes", {}).get("known_user_agents") + if not known_agents: + return + ua = self._headers.get("User-Agent", "") + if not any(ua.startswith(agent) for agent in known_agents): + warnings.warn( + f"User-Agent {ua!r} is not recognised by this datalab server. " + f"Versions saved via this client will not be attributed as agent saves. " + f"Known agents: {known_agents}", + stacklevel=3, + ) def _detect_api_url(self) -> None: """Perform a handshake with the chosen URL to ascertain the correct API URL.