Skip to content

Commit 3fd63d3

Browse files
mjvogelsongAuto-format Bot
andauthored
(small) Add SDK version to API requests (#135)
Co-authored-by: Auto-format Bot <[email protected]>
1 parent b22d98f commit 3fd63d3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/groundlight/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
# Imports from our code
66
from .client import Groundlight
77
from .binary_labels import Label
8+
from .version import get_version
89

9-
try:
10-
import importlib.metadata
11-
12-
# Copy the version number from where it's set in pyproject.toml
13-
__version__ = importlib.metadata.version("groundlight")
14-
except ModuleNotFoundError:
15-
# importlib.metadata was only added in py3.8
16-
# We're still supporting py3.7
17-
__version__ = "(version number available in python 3.8+)"
10+
__version__ = get_version()

src/groundlight/internalapi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from groundlight.images import ByteStreamWrapper
1616
from groundlight.status_codes import is_ok
17+
from groundlight.version import get_version
1718

1819
logger = logging.getLogger("groundlight.sdk")
1920

@@ -186,6 +187,9 @@ def _headers(self) -> dict:
186187
"Content-Type": "application/json",
187188
"x-api-token": self.configuration.api_key["ApiToken"],
188189
"X-Request-Id": request_id,
190+
# This metadata helps us debug issues with specific SDK versions.
191+
"x-sdk-version": get_version(),
192+
"x-sdk-language": "python",
189193
}
190194

191195
@RequestsRetryDecorator()

src/groundlight/version.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def get_version() -> str:
2+
try:
3+
import importlib.metadata # pylint: disable=import-outside-toplevel
4+
5+
# Copy the version number from where it's set in pyproject.toml
6+
return importlib.metadata.version("groundlight")
7+
except ModuleNotFoundError:
8+
# importlib.metadata was only added in py3.8
9+
# We're still supporting py3.7
10+
return "(version number available in python 3.8+)"

0 commit comments

Comments
 (0)