Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ wiremock/wiremock-mappings.json
# Wire test with manual fix: transcribe_file() requires request=bytes parameter
tests/wire/test_listen_v1_media.py

# WebSocket socket clients: optional message parameter defaults for send_flush,
# send_close, send_clear, send_finalize, send_close_stream, send_keep_alive
# WebSocket socket clients:
# - Optional message parameter defaults for send_flush, send_close, send_clear,
# send_finalize, send_close_stream, send_keep_alive
# - Removed unused imports (JSONDecodeError, websockets) flagged by ruff F401
src/deepgram/speak/v1/socket_client.py
src/deepgram/listen/v1/socket_client.py
src/deepgram/listen/v2/socket_client.py
Expand Down Expand Up @@ -41,7 +43,7 @@ src/deepgram/helpers
# - transport_interface.py: Protocol definitions (SyncTransport, AsyncTransport) for
# users implementing custom transports. This is the public-facing interface file.
# - transport.py: Internal shims, install/restore helpers, and conflict guard.
# - transports/: Concrete transport implementations (e.g. SageMaker).
# - transports/: Module stub (SageMaker transport moved to separate deepgram-sagemaker package).
# All are manually maintained and should not be regenerated.
src/deepgram/transport_interface.py
src/deepgram/transport.py
Expand Down
39 changes: 0 additions & 39 deletions .github/workflows/changelog-log.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### Features

* **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))
* **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))
* **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))
* 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))
* **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))

Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,15 @@ client = DeepgramClient(
)
```

### Custom WebSocket Transport
### Custom Transports

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.

Implement the `SyncTransport` or `AsyncTransport` protocol from `deepgram.transport_interface` and pass your class as `transport_factory`:
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.

#### Sync transports

Implement `send()`, `recv()`, `__iter__()`, and `close()`, then pass the class to `DeepgramClient`:

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

For async transports, implement `async def send()`, `async def recv()`, `async def __aiter__()`, and `async def close()`, then use `AsyncDeepgramClient`:
#### Async transports

Implement `async def send()`, `async def recv()`, `async def __aiter__()`, and `async def close()`, then use `AsyncDeepgramClient`:

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

See `src/deepgram/transport_interface.py` for the full protocol definitions.
See `src/deepgram/transport_interface.py` for the full protocol definitions (`SyncTransport` and `AsyncTransport`).

### SageMaker Transport
#### SageMaker transport

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`:
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`:

```bash
pip install deepgram-sagemaker # requires Python 3.12+
```

```python
from deepgram import AsyncDeepgramClient
from deepgram.transports.sagemaker import SageMakerTransportFactory
from deepgram_sagemaker import SageMakerTransportFactory

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

> **Note:** The SageMaker transport is async-only and requires `AsyncDeepgramClient`.

Install the SageMaker transport dependencies (requires Python 3.12+):
```bash
pip install aws-sdk-sagemaker-runtime-http2 boto3
```

See [`examples/27-transcription-live-sagemaker.py`](./examples/27-transcription-live-sagemaker.py) for a complete working example.

### Retry Configuration
Expand Down
4 changes: 2 additions & 2 deletions examples/27-transcription-live-sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Requirements::

pip install aws-sdk-sagemaker-runtime-http2 boto3
pip install deepgram-sagemaker

Environment:
AWS credentials must be configured (via environment variables,
Expand Down Expand Up @@ -41,7 +41,7 @@
ListenV1SpeechStarted,
ListenV1UtteranceEnd,
)
from deepgram.transports.sagemaker import SageMakerTransportFactory
from deepgram_sagemaker import SageMakerTransportFactory

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

Expand Down
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ asyncio_mode = "auto"
[tool.mypy]
plugins = ["pydantic.mypy"]

[[tool.mypy.overrides]]
module = [
"aws_sdk_sagemaker_runtime_http2.*",
"smithy_aws_core.*",
"boto3.*",
]
ignore_missing_imports = true

[tool.ruff]
line-length = 120

Expand Down
2 changes: 0 additions & 2 deletions src/deepgram/agent/v1/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import json
import typing
from json.decoder import JSONDecodeError

import websockets
import websockets.sync.connection as websockets_sync_connection
from ...core.events import EventEmitterMixin, EventType
from ...core.pydantic_utilities import parse_obj_as
Expand Down
2 changes: 0 additions & 2 deletions src/deepgram/listen/v1/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import json
import typing
from json.decoder import JSONDecodeError

import websockets
import websockets.sync.connection as websockets_sync_connection
from ...core.events import EventEmitterMixin, EventType
from ...core.pydantic_utilities import parse_obj_as
Expand Down
2 changes: 0 additions & 2 deletions src/deepgram/listen/v2/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import json
import typing
from json.decoder import JSONDecodeError

import websockets
import websockets.sync.connection as websockets_sync_connection
from ...core.events import EventEmitterMixin, EventType
from ...core.pydantic_utilities import parse_obj_as
Expand Down
2 changes: 0 additions & 2 deletions src/deepgram/speak/v1/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import json
import typing
from json.decoder import JSONDecodeError

import websockets
import websockets.sync.connection as websockets_sync_connection
from ...core.events import EventEmitterMixin, EventType
from ...core.pydantic_utilities import parse_obj_as
Expand Down
13 changes: 4 additions & 9 deletions src/deepgram/transports/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"""Concrete transport implementations for the Deepgram Python SDK.

Each module provides a transport factory that can be passed to
``AsyncDeepgramClient(transport_factory=...)`` or
``DeepgramClient(transport_factory=...)``.
Custom transports can be passed to ``AsyncDeepgramClient(transport_factory=...)``
or ``DeepgramClient(transport_factory=...)``.

Available transports:

- :mod:`deepgram.transports.sagemaker` — AWS SageMaker HTTP/2 BiDi streaming (async-only)
See ``deepgram.transport_interface`` for the protocol definitions.
"""

from .sagemaker import SageMakerTransport, SageMakerTransportFactory

__all__ = ["SageMakerTransport", "SageMakerTransportFactory"]
__all__: list = []
Loading