Skip to main content

Python SDK for RedenLab ML inference service

Project description

RedenLab Extract SDK

Python SDK for RedenLab's ML inference service. Run machine learning models on audio files using RedenLab's proprietary endpoints.

Features

  • JWT-based authentication — browser login for humans, env vars for machines
  • Simple session + client pattern: upload once, run any model
  • Async job management with polling and progress callbacks
  • Automatic chunking for long audio files
  • Built-in retry logic and error handling

Installation

pip install redenlab-extract

Authentication

The SDK uses JWT tokens issued by AWS Cognito. Two modes are auto-detected:

Human / Interactive (PKCE)

Run once from the terminal:

redenlab login

This opens a browser, authenticates you, and stores tokens in ~/.redenlab-ml/credentials.yaml. The SDK refreshes tokens silently — you only need to run redenlab login again if your session expires.

Machine / Headless (Client Credentials)

Set environment variables before running your script:

export REDENLAB_CLIENT_ID=your-client-id
export REDENLAB_CLIENT_SECRET=your-client-secret

The SDK detects these and fetches a token automatically. No browser, no disk tokens.

Priority: if both env vars are set, Client Credentials is used regardless of any stored PKCE tokens.

Quick Start

from redenlab_extract import RedenLabSession, intelligibility_client, run_inference

session = RedenLabSession()
client = intelligibility_client(session, model_name="als-intelligibility-v1")

result = run_inference(session, client, "audio.wav")
print(result["result"]["intelligibility_score"])
from redenlab_extract import RedenLabSession, TranscribeClient, run_inference

session = RedenLabSession()
client = TranscribeClient(session, language_code="en-US")

result = run_inference(session, client, "audio.wav")
print(result["transcript"])

Available Models

Intelligibility

from redenlab_extract import intelligibility_client

client = intelligibility_client(session, model_name="als-intelligibility-v1")
# model_name options: "als-intelligibility-v1", "als-intelligibility-v2",
#                     "ataxia-intelligibility"

Naturalness

from redenlab_extract import naturalness_client

client = naturalness_client(session, model_name="als-naturalness-v1")
# model_name options: "als-naturalness-v1", "als-naturalness-v2",
#                     "ataxia-naturalness"

Transcription (AWS Transcribe)

from redenlab_extract import TranscribeClient

client = TranscribeClient(
    session,
    language_code="en-US",   # optional, defaults to "en-US"
    max_speaker_count=4,      # optional, defaults to 10
)

WhisperX

from redenlab_extract import whisperX_client

client = whisperX_client(session, diarize=True, batch_size=16)

Speaker Counter

from redenlab_extract import speaker_counter_client

client = speaker_counter_client(session)

Speaker Diarization

from redenlab_extract import speaker_diarization_client

client = speaker_diarization_client(session)

Sylber Time

from redenlab_extract import sylber_time_client

client = sylber_time_client(session)

Usage Patterns

Level 1 — run_inference() (recommended)

Handles upload, chunking, and inference in one call:

from redenlab_extract import RedenLabSession, intelligibility_client, run_inference

session = RedenLabSession()
client = intelligibility_client(session, model_name="als-intelligibility-v1")

result = run_inference(session, client, "audio.wav")

Long files are chunked automatically and results are aggregated.

Level 2 — Upload → Submit → Poll

Useful for batch processing or when you want to decouple upload from inference:

# Upload
asset = session.upload("audio.wav")

# Submit (with retry for async S3 processing)
job_id = client._submit_with_upload_wait(asset)

# Poll
result = client.poll(job_id, timeout=600)

Level 3 — Batch processing

Submit all jobs first, then poll concurrently:

# Upload and submit all files
assets = [session.upload(f) for f in audio_files]
job_ids = [client._submit_with_upload_wait(asset) for asset in assets]

# Poll each
results = [client.poll(job_id) for job_id in job_ids]

Progress callbacks

def on_progress(status):
    print(f"Status: {status['status']}")

result = run_inference(session, client, "audio.wav", progress_callback=on_progress)

Chunked inference (long files)

run_inference() chunks automatically. For manual control:

from redenlab_extract import run_chunked_inference, aggregate_results

chunks = run_chunked_inference(session, client, "long_audio.wav", chunk_duration=50)
result = aggregate_results(chunks, score_key="intelligibility_score")

Backend warmup

SageMaker-backed models (intelligibility, naturalness) may be cold after inactivity:

health = client.health()
if not health["ready"]:
    client.warmup()  # submits a dummy job to wake the endpoint

Configuration

Base URL

Resolved in priority order:

Source How
Constructor RedenLabSession(base_url="https://...")
Environment variable REDENLAB_ML_BASE_URL=https://...
Config file ~/.redenlab-ml/config.yamlbase_url: ...
Service discovery Automatic fallback

Config file (~/.redenlab-ml/config.yaml)

base_url: https://your-api-gateway-url.amazonaws.com/prod  # optional

Credentials file (~/.redenlab-ml/credentials.yaml)

Written automatically by redenlab login. Do not edit manually.

Supported File Types

  • WAV (.wav)
  • FLAC (.flac)
  • MP3 (.mp3)
  • OGG (.ogg)
  • M4A (.m4a)

Requirements

  • Python 3.10+
  • requests
  • tenacity
  • pyyaml

Optional (for audio chunking):

  • soundfile
  • numpy

Support

License

MIT License — see LICENSE for details.

Changelog

See CHANGELOG.md for version history.

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

redenlab_extract-1.3.0.tar.gz (96.0 kB view details)

Uploaded Source

Built Distribution

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

redenlab_extract-1.3.0-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file redenlab_extract-1.3.0.tar.gz.

File metadata

  • Download URL: redenlab_extract-1.3.0.tar.gz
  • Upload date:
  • Size: 96.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for redenlab_extract-1.3.0.tar.gz
Algorithm Hash digest
SHA256 b7110a06483b8b875723b7e06f1f7aff71af076cec675b8d861be4935ec84981
MD5 c4111a68fddca2b87b0b96730c94446b
BLAKE2b-256 4605687e31bdcdbc2586d95f01940e0abc6b7388fb18d412f867dd6e473e25fb

See more details on using hashes here.

File details

Details for the file redenlab_extract-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for redenlab_extract-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49034c15da26459406d615d500437401cd5611fc06a4c7347a9ed292ca9d8d62
MD5 98d9135c1a59f5fa588e9bf1a23aa61d
BLAKE2b-256 0ff208487d63c0c525355bac0f4927164e28c5e1f675ddf32117b2c8a5ef9c95

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