Skip to content

Commit 4a5aa0f

Browse files
committed
feat(python/sdk): add user-agent for SDK tracking and __version__.py (#5377)
GitOrigin-RevId: b06c167a832762a758290346a2fa42fa42df3d45
1 parent 14e0172 commit 4a5aa0f

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

assemblyai/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from . import extras
2+
from .__version__ import __version__
23
from .client import Client
34
from .lemur import Lemur
45
from .transcriber import RealtimeTranscriber, Transcriber, Transcript, TranscriptGroup
@@ -139,4 +140,6 @@
139140
"settings",
140141
# packages
141142
"extras",
143+
# version
144+
"__version__",
142145
]

assemblyai/__version__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.28.0"

assemblyai/client.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import sys
12
import threading
23
from typing import ClassVar, Optional
34

45
import httpx
56
from typing_extensions import Self
67

7-
from . import types
8+
from . import __version__, types
89

910

1011
class Client:
@@ -33,19 +34,19 @@ def __init__(
3334
"Please provide an API key via the ASSEMBLYAI_API_KEY environment variable or the global settings."
3435
)
3536

37+
vi = sys.version_info
38+
python_version = f"{vi.major}.{vi.minor}.{vi.micro}"
39+
user_agent = f"{httpx._client.USER_AGENT} AssemblyAI/1.0 (sdk=Python/{__version__} runtime_env=Python/{python_version})"
40+
41+
headers = {"user-agent": user_agent}
3642
if self._settings.api_key:
37-
self._http_client = httpx.Client(
38-
base_url=self.settings.base_url,
39-
headers={
40-
"authorization": self.settings.api_key,
41-
},
42-
timeout=self.settings.http_timeout,
43-
)
44-
else:
45-
self._http_client = httpx.Client(
46-
base_url=self.settings.base_url,
47-
timeout=self.settings.http_timeout,
48-
)
43+
headers["authorization"] = self.settings.api_key
44+
45+
self._http_client = httpx.Client(
46+
base_url=self.settings.base_url,
47+
headers=headers,
48+
timeout=self.settings.http_timeout,
49+
)
4950

5051
@property
5152
def settings(self) -> types.Settings:

setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
long_description = (Path(__file__).parent / "README.md").read_text()
66

77

8+
def get_version() -> str:
9+
version = {}
10+
with open(Path(__file__).parent / "assemblyai" / "__version__.py") as f:
11+
exec(f.read(), version)
12+
return version["__version__"]
13+
14+
815
setup(
916
name="assemblyai",
10-
version="0.28.0",
17+
version=get_version(),
1118
description="AssemblyAI Python SDK",
1219
author="AssemblyAI",
1320
author_email="engineering.sdk@assemblyai.com",

0 commit comments

Comments
 (0)