Skip to content

Commit 16d500e

Browse files
authored
refactor(sagemaker): move SageMaker transport to separate package (#662)
## Summary - Move the SageMaker transport out of the SDK into a standalone [`deepgram-sagemaker`](https://github.com/deepgram/deepgram-python-sdk-transport-sagemaker) package, since its AWS dependencies require Python >=3.12 but the SDK supports >=3.8 - Consolidate the README's "Custom WebSocket Transport" and "SageMaker Transport" sections into a single "Custom Transports" section that explains the concept, shows how to build one (sync + async), and uses `deepgram-sagemaker` as the real-world example - Remove unused imports (`JSONDecodeError`, `websockets`) from socket client files flagged by ruff F401 ## Changes | File | Change | |------|--------| | `src/deepgram/transports/sagemaker.py` | Deleted — moved to `deepgram-sagemaker` package | | `src/deepgram/transports/__init__.py` | Cleared SageMaker exports | | `pyproject.toml` | Removed mypy overrides for AWS SDK modules | | `README.md` | Consolidated custom transports section with `deepgram-sagemaker` example | | `examples/27-transcription-live-sagemaker.py` | Updated imports and install instructions | | `src/deepgram/*/socket_client.py` (×4) | Removed unused imports | | `.fernignore` | Updated comments | ## Test plan - [x] `ruff check src/` passes - [x] `mypy src/deepgram/transports/` passes - [x] No remaining `sagemaker`/`SageMaker` references in `src/deepgram/` - [x] New `deepgram-sagemaker` package structure verified in `../deepgram-python-sdk-transport-sagemaker/` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 4ba94d4 commit 16d500e

File tree

12 files changed

+29
-445
lines changed

12 files changed

+29
-445
lines changed

.fernignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ wiremock/wiremock-mappings.json
1111
# Wire test with manual fix: transcribe_file() requires request=bytes parameter
1212
tests/wire/test_listen_v1_media.py
1313

14-
# WebSocket socket clients: optional message parameter defaults for send_flush,
15-
# send_close, send_clear, send_finalize, send_close_stream, send_keep_alive
14+
# WebSocket socket clients:
15+
# - Optional message parameter defaults for send_flush, send_close, send_clear,
16+
# send_finalize, send_close_stream, send_keep_alive
17+
# - Removed unused imports (JSONDecodeError, websockets) flagged by ruff F401
1618
src/deepgram/speak/v1/socket_client.py
1719
src/deepgram/listen/v1/socket_client.py
1820
src/deepgram/listen/v2/socket_client.py
@@ -41,7 +43,7 @@ src/deepgram/helpers
4143
# - transport_interface.py: Protocol definitions (SyncTransport, AsyncTransport) for
4244
# users implementing custom transports. This is the public-facing interface file.
4345
# - transport.py: Internal shims, install/restore helpers, and conflict guard.
44-
# - transports/: Concrete transport implementations (e.g. SageMaker).
46+
# - transports/: Module stub (SageMaker transport moved to separate deepgram-sagemaker package).
4547
# All are manually maintained and should not be regenerated.
4648
src/deepgram/transport_interface.py
4749
src/deepgram/transport.py

.github/workflows/changelog-log.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
### Features
1111

1212
* **helpers:** add TextBuilder class for TTS pronunciation and pause controls ([#660](https://github.com/deepgram/deepgram-python-sdk/issues/660)) ([4324120](https://github.com/deepgram/deepgram-python-sdk/commit/43241200a7e025bdc4633bdb47f6708921c82ad1))
13-
* **sagemaker:** add SageMaker transport for running Deepgram on AWS SageMaker endpoints ([#659](https://github.com/deepgram/deepgram-python-sdk/issues/659)) ([2046175](https://github.com/deepgram/deepgram-python-sdk/commit/204617538339b1958e2fe562dc94c8887de94a5d))
13+
* **sagemaker:** add SageMaker transport support via the separate [`deepgram-sagemaker`](https://pypi.org/project/deepgram-sagemaker/) package (`pip install deepgram-sagemaker`) ([#659](https://github.com/deepgram/deepgram-python-sdk/issues/659))
1414
* v6 — fully generated SDK with latest APIs and WebSocket support ([#640](https://github.com/deepgram/deepgram-python-sdk/issues/640)) ([bc918fe](https://github.com/deepgram/deepgram-python-sdk/commit/bc918fe23e92eefb5e4c24cbfaad369d4e2818f3))
1515
* **websockets:** add custom WebSocket transport support ([#658](https://github.com/deepgram/deepgram-python-sdk/issues/658)) ([f6cf0fb](https://github.com/deepgram/deepgram-python-sdk/commit/f6cf0fbc9aaaa844e475e014560cc377819ec1f9))
1616

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,15 @@ client = DeepgramClient(
335335
)
336336
```
337337

338-
### Custom WebSocket Transport
338+
### Custom Transports
339339

340340
Replace the built-in `websockets` transport with your own implementation for WebSocket-based APIs (Listen, Speak, Agent). This enables alternative protocols (HTTP/2, SSE), test doubles, or proxied connections.
341341

342-
Implement the `SyncTransport` or `AsyncTransport` protocol from `deepgram.transport_interface` and pass your class as `transport_factory`:
342+
Any class that implements the right methods can be used as a transport — no inheritance required. Pass your class (or a factory callable) as `transport_factory` when creating a client.
343+
344+
#### Sync transports
345+
346+
Implement `send()`, `recv()`, `__iter__()`, and `close()`, then pass the class to `DeepgramClient`:
343347

344348
```python
345349
from deepgram import DeepgramClient
@@ -361,7 +365,9 @@ with client.listen.v1.connect(model="nova-3") as connection:
361365
connection.start_listening()
362366
```
363367

364-
For async transports, implement `async def send()`, `async def recv()`, `async def __aiter__()`, and `async def close()`, then use `AsyncDeepgramClient`:
368+
#### Async transports
369+
370+
Implement `async def send()`, `async def recv()`, `async def __aiter__()`, and `async def close()`, then use `AsyncDeepgramClient`:
365371

366372
```python
367373
from deepgram import AsyncDeepgramClient
@@ -373,15 +379,19 @@ async with client.listen.v1.connect(model="nova-3") as connection:
373379
await connection.start_listening()
374380
```
375381

376-
See `src/deepgram/transport_interface.py` for the full protocol definitions.
382+
See `src/deepgram/transport_interface.py` for the full protocol definitions (`SyncTransport` and `AsyncTransport`).
377383

378-
### SageMaker Transport
384+
#### SageMaker transport
379385

380-
The SDK includes a built-in transport for running Deepgram models on [AWS SageMaker](https://aws.amazon.com/sagemaker/) endpoints. It uses HTTP/2 bidirectional streaming under the hood, but exposes the same SDK interface — just swap in a `transport_factory`:
386+
The [`deepgram-sagemaker`](https://pypi.org/project/deepgram-sagemaker/) package ([source](https://github.com/deepgram/deepgram-python-sdk-transport-sagemaker)) is a ready-made async transport for running Deepgram models on [AWS SageMaker](https://aws.amazon.com/sagemaker/) endpoints. It uses HTTP/2 bidirectional streaming under the hood, but exposes the same SDK interface — just install the package and swap in a `transport_factory`:
387+
388+
```bash
389+
pip install deepgram-sagemaker # requires Python 3.12+
390+
```
381391

382392
```python
383393
from deepgram import AsyncDeepgramClient
384-
from deepgram.transports.sagemaker import SageMakerTransportFactory
394+
from deepgram_sagemaker import SageMakerTransportFactory
385395

386396
factory = SageMakerTransportFactory(
387397
endpoint_name="my-deepgram-endpoint",
@@ -398,11 +408,6 @@ async with client.listen.v1.connect(model="nova-3") as connection:
398408

399409
> **Note:** The SageMaker transport is async-only and requires `AsyncDeepgramClient`.
400410
401-
Install the SageMaker transport dependencies (requires Python 3.12+):
402-
```bash
403-
pip install aws-sdk-sagemaker-runtime-http2 boto3
404-
```
405-
406411
See [`examples/27-transcription-live-sagemaker.py`](./examples/27-transcription-live-sagemaker.py) for a complete working example.
407412

408413
### Retry Configuration

examples/27-transcription-live-sagemaker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Requirements::
1515
16-
pip install aws-sdk-sagemaker-runtime-http2 boto3
16+
pip install deepgram-sagemaker
1717
1818
Environment:
1919
AWS credentials must be configured (via environment variables,
@@ -41,7 +41,7 @@
4141
ListenV1SpeechStarted,
4242
ListenV1UtteranceEnd,
4343
)
44-
from deepgram.transports.sagemaker import SageMakerTransportFactory
44+
from deepgram_sagemaker import SageMakerTransportFactory
4545

4646
ListenV1SocketClientResponse = Union[ListenV1Results, ListenV1Metadata, ListenV1UtteranceEnd, ListenV1SpeechStarted]
4747

pyproject.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ asyncio_mode = "auto"
6464
[tool.mypy]
6565
plugins = ["pydantic.mypy"]
6666

67-
[[tool.mypy.overrides]]
68-
module = [
69-
"aws_sdk_sagemaker_runtime_http2.*",
70-
"smithy_aws_core.*",
71-
"boto3.*",
72-
]
73-
ignore_missing_imports = true
74-
7567
[tool.ruff]
7668
line-length = 120
7769

src/deepgram/agent/v1/socket_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import json
44
import typing
5-
from json.decoder import JSONDecodeError
65

7-
import websockets
86
import websockets.sync.connection as websockets_sync_connection
97
from ...core.events import EventEmitterMixin, EventType
108
from ...core.pydantic_utilities import parse_obj_as

src/deepgram/listen/v1/socket_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import json
44
import typing
5-
from json.decoder import JSONDecodeError
65

7-
import websockets
86
import websockets.sync.connection as websockets_sync_connection
97
from ...core.events import EventEmitterMixin, EventType
108
from ...core.pydantic_utilities import parse_obj_as

src/deepgram/listen/v2/socket_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import json
44
import typing
5-
from json.decoder import JSONDecodeError
65

7-
import websockets
86
import websockets.sync.connection as websockets_sync_connection
97
from ...core.events import EventEmitterMixin, EventType
108
from ...core.pydantic_utilities import parse_obj_as

src/deepgram/speak/v1/socket_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import json
44
import typing
5-
from json.decoder import JSONDecodeError
65

7-
import websockets
86
import websockets.sync.connection as websockets_sync_connection
97
from ...core.events import EventEmitterMixin, EventType
108
from ...core.pydantic_utilities import parse_obj_as

0 commit comments

Comments
 (0)