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 AWS SageMaker async inference endpoints.
Features
- Simple, Pythonic API for ML inference
- Automatic file upload to S3
- Async job management with polling
- Built-in retry logic and error handling
- Support for multiple ML models (intelligibility, speaker diarization, etc.)
Installation
pip install redenlab-extract
Quick Start
from redenlab_ml import InferenceClient
# Initialize client with API key
client = InferenceClient(api_key="sk_live_your_api_key_here")
# Run inference on an audio file
result = client.predict(file_path="audio.wav")
print(result)
# {
# 'job_id': 'uuid',
# 'status': 'completed',
# 'result': {'intelligibility_score': 0.85},
# 'created_at': '2025-01-15T10:30:00Z',
# 'completed_at': '2025-01-15T10:35:00Z'
# }
Authentication
The SDK looks for your API key in the following order:
- Constructor parameter:
InferenceClient(api_key="sk_live_...") - Environment variable:
REDENLAB_ML_API_KEY - Config file:
~/.redenlab-ml/config.yaml
Using Environment Variables
export REDENLAB_ML_API_KEY=sk_live_your_api_key_here
from redenlab_ml import InferenceClient
# API key is loaded from environment
client = InferenceClient()
result = client.predict(file_path="audio.wav")
Using Config File
Create ~/.redenlab-ml/config.yaml:
api_key: sk_live_your_api_key_here
base_url: https://your-api-gateway-url.amazonaws.com/prod # optional
model_name: intelligibility # optional
from redenlab_ml import InferenceClient
# API key is loaded from config file
client = InferenceClient()
result = client.predict(file_path="audio.wav")
Advanced Usage
Specify Model
client = InferenceClient(
api_key="sk_live_...",
model_name="speaker_diarisation_workflow"
)
Available models:
intelligibility(default)speaker_diarisation_workflowataxia-naturalnessataxia-intelligibility
Custom Timeout
client = InferenceClient(
api_key="sk_live_...",
timeout=7200 # 2 hours
)
Batch Processing (Submit + Poll Pattern)
For processing multiple files efficiently, use submit() and poll() separately:
# Submit all jobs first (fast - no waiting)
job_ids = []
for audio_file in audio_files:
job_id = client.submit(file_path=audio_file)
job_ids.append(job_id)
print(f"Submitted: {job_id}")
# Poll for results (efficient - single loop checking all jobs)
results = {}
pending = set(job_ids)
while pending:
for job_id in list(pending):
status = client.get_status(job_id)
if status['status'] == 'completed':
results[job_id] = status['result']
pending.remove(job_id)
elif status['status'] == 'failed':
results[job_id] = {'error': status.get('error')}
pending.remove(job_id)
if pending:
time.sleep(10) # Check all jobs every 10 seconds
print(f"Processed {len(results)} files!")
Submit and Poll Separately
# Submit job and get job_id immediately
job_id = client.submit(file_path="audio.wav")
print(f"Job submitted: {job_id}")
# ... do other work, or even exit and resume later ...
# Poll when ready
result = client.poll(job_id)
print(result['result'])
Check Job Status (Non-blocking)
# Get status of a running job without blocking
status = client.get_status(job_id="existing-job-uuid")
print(status['status']) # 'upload_pending', 'processing', 'completed', 'failed'
Error Handling
from redenlab_ml import InferenceClient, InferenceError, TimeoutError, AuthenticationError
try:
client = InferenceClient(api_key="sk_live_...")
result = client.predict(file_path="audio.wav")
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except TimeoutError as e:
print(f"Inference timed out: {e}")
except InferenceError as e:
print(f"Inference failed: {e}")
Configuration Options
| Parameter | Environment Variable | Config File | Default |
|---|---|---|---|
api_key |
REDENLAB_ML_API_KEY |
api_key |
Required |
base_url |
REDENLAB_ML_BASE_URL |
base_url |
Production endpoint |
model_name |
REDENLAB_ML_MODEL |
model_name |
intelligibility |
timeout |
REDENLAB_ML_TIMEOUT |
timeout |
3600 (1 hour) |
Supported File Types
- WAV (
.wav) - MP3 (
.mp3) - M4A (
.m4a) - FLAC (
.flac)
Requirements
- Python 3.8+
requeststenacitypyyaml
Development
Install Development Dependencies
# Clone from CodeCommit (requires AWS credentials)
git clone ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/redenlab-extract
cd redenlab-extract
pip install -e ".[dev]"
Run Tests
pytest tests/
Code Formatting
black src/ tests/
ruff check src/ tests/
Type Checking
mypy src/
Examples
See the examples/ directory for more usage examples:
- quickstart.py - Basic usage
- batch_inference.py - Process multiple files
- error_handling.py - Robust error handling
Documentation
Support
- Email: support@redenlab.com
- Website: https://redenlab.com
License
MIT License - see LICENSE file for details
Changelog
See CHANGELOG.md for version history and release notes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file redenlab_extract-0.3.0.tar.gz.
File metadata
- Download URL: redenlab_extract-0.3.0.tar.gz
- Upload date:
- Size: 76.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40932bf2fdd4320242b27b59e7e6bf1d01bc87b9fec518e788d1404f25b80315
|
|
| MD5 |
54d4ded87fd72d305e79f1f2bffc469f
|
|
| BLAKE2b-256 |
fde6335572cbc74e047fbf60c4936b97a05aea953a7ab5a448346feb2cd4458e
|
File details
Details for the file redenlab_extract-0.3.0-py3-none-any.whl.
File metadata
- Download URL: redenlab_extract-0.3.0-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50447fe67cf576a1754697ed7af6c4ca421adca6f836240f17192d1bd3d5b32d
|
|
| MD5 |
abc22dc0c670844f99d5700a91e206ce
|
|
| BLAKE2b-256 |
89acd9d0204d8c124ad1a469b126995cb30e1db706d79201f655152865b4a0eb
|