Skip to main content

Python SDK for avatar WebSocket services with audio streaming and animation frame reception

Project description

Spatius Python SDK

Python server SDK for creating Spatius avatar sessions.

Installation

pip install spatius

Install the optional Ogg Opus encoder support when you want the SDK to encode raw PCM before sending:

pip install "spatius[opus]"

Quick Start

import asyncio
from datetime import datetime, timedelta, timezone

from spatius import new_avatar_session


async def main():
    session = new_avatar_session(
        api_key="your-api-key",
        app_id="your-app-id",
        avatar_id="your-avatar-id",
        expire_at=datetime.now(timezone.utc) + timedelta(minutes=5),
        transport_frames=lambda frame, last: print(
            f"Received frame: {len(frame)} bytes, last={last}"
        ),
        on_error=lambda err: print(f"Session error: {err}"),
        on_close=lambda: print("Session closed"),
    )

    await session.init()
    connection_id = await session.start()
    print(f"Connected: {connection_id}")

    audio_data = b"..."  # mono PCM s16le audio bytes
    request_id = await session.send_audio(audio_data, end=True)
    print(f"Sent audio request: {request_id}")

    await asyncio.sleep(10)
    await session.close()


if __name__ == "__main__":
    asyncio.run(main())

Benchmarks

Benchmark the built-in PCM to Ogg Opus encoder from a source checkout:

uv run --extra opus python benchmarks/bench_ogg_opus_encoder.py

Use --help to see options for sample rate, bitrate, frame duration, input chunk size, and run count.

Documentation

See the full Python SDK guide at docs.spatius.ai/sdk-reference/python-sdk/python-sdk.

License

MIT

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

spatius-1.0.4rc2.tar.gz (129.8 kB view details)

Uploaded Source

Built Distribution

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

spatius-1.0.4rc2-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file spatius-1.0.4rc2.tar.gz.

File metadata

  • Download URL: spatius-1.0.4rc2.tar.gz
  • Upload date:
  • Size: 129.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spatius-1.0.4rc2.tar.gz
Algorithm Hash digest
SHA256 58d94935f2768c7f10425d4279179512e70349f33068d69dc6ed62635392fece
MD5 5fcf2ad685c8592f7cd94c5ef2b94738
BLAKE2b-256 2bff1f4fe372aea96faddaa25f21218d56a5b653f12e682822e15d6c2ee659fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for spatius-1.0.4rc2.tar.gz:

Publisher: publish.yml on spatius-ai/spatius-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spatius-1.0.4rc2-py3-none-any.whl.

File metadata

  • Download URL: spatius-1.0.4rc2-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spatius-1.0.4rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 5ad5a7104394ca69faf200431edd59a4df3a52ecaf19565254d2abc028598c34
MD5 44fe86a1611d9cc24f2c13d8e23deed8
BLAKE2b-256 e0fcdb4cd6c523e6df3e9c772c71634ea920aac7f5206b97c7a8aecc9ff0ff4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for spatius-1.0.4rc2-py3-none-any.whl:

Publisher: publish.yml on spatius-ai/spatius-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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