Skip to main content

The official Python SDK for the Soniox API (STT, REST)

Project description

Soniox Python SDK

The SDK exposes two clients: SonioxClient (sync) and AsyncSonioxClient. Client can hit every Soniox REST endpoint or open a real-time websocket session, so you can focus on building features instead of dealing with boilerplate. Auth, file uploads, transcription polling, webhook helpers, and real-time stream helpers all live in one typed package.

Install

pip install soniox
# or if using uv
uv add soniox
export SONIOX_API_KEY=<your-key>

Get your API key from the Soniox Console and inject it once per shell session. Both clients read SONIOX_API_KEY by default, but you can override it per-client if needed.

Quick run (rest + real-time)

  1. REST transcription: copy this snippet or run examples/soniox_client/api_example.py.
from soniox import SonioxClient

client = SonioxClient()
transcription = client.stt.transcribe(
    audio_url="https://soniox.com/media/examples/coffee_shop.mp3",
    client_reference_id="docs-quick-start",
)
client.stt.wait(transcription.id, timeout_sec=60)
print(client.stt.get_transcript(transcription.id).text[:200])
  1. Real-time streaming: the real-time helpers mirror the sync rest sample—open client.realtime.stt.connect, call session.send_byte_chunk or session.send_bytes, then iterate session.receive_events() to render tokens. example:
from soniox import SonioxClient
from soniox.types import RealtimeSTTConfig, Token
from soniox.utils import render_tokens, throttle_audio, start_audio_thread

DEMO_FILE = "path_to_your_audio_file"

client = SonioxClient()
config = RealtimeSTTConfig(model="stt-rt-v4", audio_format="mp3")
final_tokens: list[Token] = []
non_final_tokens: list[Token] = []

def realtime():
    with client.realtime.stt.connect(config=config) as session:
        start_audio_thread(session, throttle_audio(DEMO_FILE, delay_seconds=0.1))
        for event in session.receive_events():
            for token in event.tokens:
                if token.is_final:
                    final_tokens.append(token)
                else:
                    non_final_tokens.append(token)
            print(render_tokens(final_tokens, non_final_tokens))
            non_final_tokens.clear()

realtime()

see examples/soniox_client/realtime_example.py for the full flow.

Repository layout

  • src/soniox/ – sdk code (clients, http namespaces, real-time/session helpers, types, utils).
  • examples/soniox_client & examples/async_soniox_client – runnable rest + real-time flows for sync and async.
  • docs/ – markdown outputs (e.g., docs/python-sdk.md) that come from pydoc-markdown.
  • assets/ – sample audio referenced by the examples.
  • tests/ – pytest narratives that describe the public behavior.

Development

uv install --with dev

This pulls in ruff, pyright, pytest, etc., so you can lint, type-check, test, and regenerate docs locally.

Docs

source .venv/bin/activate
python3 scripts/generate_docs.py

Docs are output to /docs directory.

Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

soniox-2.2.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

soniox-2.2.0-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file soniox-2.2.0.tar.gz.

File metadata

  • Download URL: soniox-2.2.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for soniox-2.2.0.tar.gz
Algorithm Hash digest
SHA256 9e73828f9b867962922fbd08f061a702088c6273987d28559f415702ce584ce1
MD5 00745cec0587c547efd4ab8eb0b1c4ab
BLAKE2b-256 5c82a45284555c30aaefe037d1c9c4f06cc35346dc85c8cd3cc5f6f9a2a4d0a5

See more details on using hashes here.

File details

Details for the file soniox-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: soniox-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for soniox-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d044988c408981d0c7f172029498bca1baed83bb96d49440aac3de4dbdc4ce7f
MD5 b87e6f478d6a241d0a406028af6cd3b1
BLAKE2b-256 09ce37c61b7ca97ceba7d23760b451750031bafb544a53c95fe415c66e37ef45

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page