Skip to content

Commit 695cfc9

Browse files
authored
Merge pull request #13 from speechmatics/client-ref-version
Add client version in client_ref when requesting a JWT
2 parents 9e4bf00 + 874ffdc commit 695cfc9

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [0.1.1] - 2025-03-26
8+
9+
### Changed
10+
11+
- Include the package version when requesting a JWT
12+
713
## [0.1.0] - 2025-02-13
814

915
### Added

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.1

speechmatics_flow/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
DebugMode,
3434
)
3535
from speechmatics_flow.tool_function_param import ToolFunctionParam
36-
from speechmatics_flow.utils import read_in_chunks, json_utf8
36+
from speechmatics_flow.utils import read_in_chunks, json_utf8, get_version
3737

3838
LOGGER = logging.getLogger(__name__)
3939

@@ -652,9 +652,10 @@ async def get_temp_token(api_key):
652652
"""
653653
Used to get a temporary token from management platform api
654654
"""
655+
version = get_version()
655656
mp_api_url = os.getenv("SM_MANAGEMENT_PLATFORM_URL", "https://mp.speechmatics.com")
656657
endpoint = f"{mp_api_url}/v1/api_keys?type=flow"
657-
body = {"ttl": 300, "client_ref": "speechmatics-flow-python-client"}
658+
body = {"ttl": 300, "sm-sdk": f"python-{version}"}
658659
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
659660
response = httpx.post(endpoint, json=body, headers=headers)
660661
response.raise_for_status()

speechmatics_flow/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import asyncio
77
import concurrent.futures
8+
import importlib.metadata
89
import inspect
910
import json
11+
from pathlib import Path
1012

1113

1214
def json_utf8(func):
@@ -50,3 +52,14 @@ async def read_in_chunks(stream, chunk_size):
5052
if not audio_chunk:
5153
break
5254
yield audio_chunk
55+
56+
57+
def get_version() -> str:
58+
"""Reads the version number from the package or VERSION file"""
59+
try:
60+
return importlib.metadata.version(__package__)
61+
except importlib.metadata.PackageNotFoundError:
62+
version_path = Path(__file__).resolve().parent.parent / "VERSION"
63+
if version_path.exists():
64+
return version_path.read_text(encoding="utf-8").strip()
65+
return "0.0.0"

0 commit comments

Comments
 (0)