This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
WaveSpeed Python SDK - Official Python SDK for WaveSpeedAI inference platform. Provides a serverless worker implementation compatible with RunPod infrastructure.
# Run all tests
python -m pytest
# Run a single test file
python -m pytest tests/test_serverless/test_modules/test_job.py
# Run a specific test
python -m pytest tests/test_serverless/test_modules/test_job.py::TestRunJob::test_sync_handler_success -v# Install in editable mode
pip install -e .
# Run handler locally with test input
python handler.py --test_input '{"input": {"message": "hello"}}'
# Run FastAPI development server
python handler.py --waverless_serve_api --waverless_api_port 8000# Build and test
./images/test_worker/build_and_test.shEntry point: serverless.start({"handler": handler}) in __init__.py
Three execution modes:
- Local test mode -
--test_inputflag ortest_input.jsonfile - API server mode -
--waverless_serve_apifor FastAPI dev server - Worker mode - Production mode polling for jobs
Key modules in modules/:
job.py- Job execution (run_job,run_job_generator,handle_job)scaler.py- Concurrent job fetching and processing (JobScaler)handler.py- Handler type detection (sync/async/generator)http.py- HTTP communication (fetch_jobs,send_result,stream_result)fastapi.py- Local development API server (WorkerAPI)local.py- Local test executionstate.py- Job and worker state managementvalidator.py- Input validation (RunPod-compatible)
Handlers can be sync/async functions or generators:
def sync_handler(job): return {"output": result}
async def async_handler(job): return {"output": result}
def generator_handler(job): yield partial_result
async def async_gen_handler(job): yield partial_resultfrom wavespeed.serverless.utils import validate
schema = {
"prompt": {"type": str, "required": True},
"temperature": {"type": float, "required": False, "default": 0.7, "constraints": lambda x: 0 <= x <= 2},
}
result = validate(job_input, schema) # Returns {"validated_input": ...} or {"errors": [...]}Auto-detects RunPod (RUNPOD_* env vars) or native Waverless (WAVERLESS_* env vars) environments.