Skip to content

Commit

Permalink
feat(python/sdk): add user-agent for SDK tracking and `__version__.py…
Browse files Browse the repository at this point in the history
…` (#5377)

GitOrigin-RevId: b06c167a832762a758290346a2fa42fa42df3d45
  • Loading branch information
ploeber committed Jun 26, 2024
1 parent 14e0172 commit 4a5aa0f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
3 changes: 3 additions & 0 deletions assemblyai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import extras
from .__version__ import __version__
from .client import Client
from .lemur import Lemur
from .transcriber import RealtimeTranscriber, Transcriber, Transcript, TranscriptGroup
Expand Down Expand Up @@ -139,4 +140,6 @@
"settings",
# packages
"extras",
# version
"__version__",
]
1 change: 1 addition & 0 deletions assemblyai/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.28.0"
27 changes: 14 additions & 13 deletions assemblyai/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys
import threading
from typing import ClassVar, Optional

import httpx
from typing_extensions import Self

from . import types
from . import __version__, types


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

vi = sys.version_info
python_version = f"{vi.major}.{vi.minor}.{vi.micro}"
user_agent = f"{httpx._client.USER_AGENT} AssemblyAI/1.0 (sdk=Python/{__version__} runtime_env=Python/{python_version})"

headers = {"user-agent": user_agent}
if self._settings.api_key:
self._http_client = httpx.Client(
base_url=self.settings.base_url,
headers={
"authorization": self.settings.api_key,
},
timeout=self.settings.http_timeout,
)
else:
self._http_client = httpx.Client(
base_url=self.settings.base_url,
timeout=self.settings.http_timeout,
)
headers["authorization"] = self.settings.api_key

self._http_client = httpx.Client(
base_url=self.settings.base_url,
headers=headers,
timeout=self.settings.http_timeout,
)

@property
def settings(self) -> types.Settings:
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
long_description = (Path(__file__).parent / "README.md").read_text()


def get_version() -> str:
version = {}
with open(Path(__file__).parent / "assemblyai" / "__version__.py") as f:
exec(f.read(), version)
return version["__version__"]


setup(
name="assemblyai",
version="0.28.0",
version=get_version(),
description="AssemblyAI Python SDK",
author="AssemblyAI",
author_email="engineering.sdk@assemblyai.com",
Expand Down

0 comments on commit 4a5aa0f

Please sign in to comment.