Skip to content

Commit 55f5e83

Browse files
committed
feat(skore-hub-project): Send a X-Skore-Client header when using HUBClient
1 parent 2cba17f commit 55f5e83

File tree

1 file changed

+15
-2
lines changed
  • skore-hub-project/src/skore_hub_project/client

1 file changed

+15
-2
lines changed

skore-hub-project/src/skore_hub_project/client/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Client exchanging with ``skore hub``."""
22

3+
import importlib
34
import logging
45
from contextlib import suppress
56
from http import HTTPStatus
@@ -132,6 +133,14 @@ def request(self, *args, **kwargs) -> Response:
132133
raise HTTPStatusError(message, request=response.request, response=response)
133134

134135

136+
PACKAGE_NAME = str.split(__name__, ".", 1)[0].replace("_", "-")
137+
PACKAGE_VERSION = (
138+
version
139+
if ((version := importlib.metadata.version(PACKAGE_NAME)) != "0.0.0+unknown")
140+
else None
141+
)
142+
143+
135144
class HUBClient(Client):
136145
"""
137146
Client exchanging with ``skore hub``.
@@ -157,10 +166,14 @@ def request(
157166
"""Execute request with authorization."""
158167
headers = Headers(headers)
159168

160-
# Overload headers with our custom headers (API key or token)
169+
# Overload headers with package version
170+
if PACKAGE_VERSION:
171+
headers.update({"X-Skore-Client": f"{PACKAGE_NAME}:{PACKAGE_VERSION}"})
172+
173+
# Overload headers with credentials
161174
if self.authenticated:
162175
if (apikey := environ.get("SKORE_HUB_API_KEY")) is not None:
163-
headers.update({"X-API-Key": f"{apikey}"})
176+
headers.update({"X-API-Key": apikey})
164177
else:
165178
headers.update({"Authorization": f"Bearer {Token.access()}"})
166179

0 commit comments

Comments
 (0)