Skip to main content

WaveSpeedAI Python Client — Official Python SDK for WaveSpeedAI inference platform

Project description

WaveSpeedAI logo

WaveSpeedAI Python SDK

Official Python SDK for the WaveSpeedAI inference platform

🌐 Visit wavespeed.ai📖 Documentation💬 Issues


Installation

pip install wavespeed

API Client

Run WaveSpeed AI models with a simple API:

import wavespeed

output = wavespeed.run(
    "wavespeed-ai/z-image/turbo",
    input={"prompt": "A cat holds a sign that says 'Hello World'"},
)

print(output["outputs"][0])  # Output URL

Authentication

Set your API key via environment variable:

export WAVESPEED_API_KEY="your-api-key"

Or pass it directly:

from wavespeed import Client

client = Client(api_key="your-api-key")
output = client.run("wavespeed-ai/z-image/turbo", input={"prompt": "A cat holds a sign that says 'Hello World'"})

Options

output = wavespeed.run(
    "wavespeed-ai/z-image/turbo",
    input={"prompt": "A cat holds a sign that says 'Hello World'"},
    timeout=36000.0     # Max wait time in seconds (default: 36000.0)
    poll_interval=1.0,  # Status check interval (default: 1.0)
)

Upload Files

Upload images, videos, or audio files:

import wavespeed

url = wavespeed.upload("/path/to/image.png")
print(url)

Serverless Worker

Build serverless workers for the WaveSpeed platform.

Basic Handler

import wavespeed.serverless as serverless

def handler(job):
    job_input = job["input"]
    result = job_input.get("prompt", "").upper()
    return {"output": result}

serverless.start({"handler": handler})

Async Handler

import wavespeed.serverless as serverless

async def handler(job):
    job_input = job["input"]
    result = await process_async(job_input)
    return {"output": result}

serverless.start({"handler": handler})

Generator Handler (Streaming)

import wavespeed.serverless as serverless

def handler(job):
    for i in range(10):
        yield {"progress": i, "partial": f"chunk-{i}"}

serverless.start({"handler": handler})

Input Validation

from wavespeed.serverless.utils import validate

INPUT_SCHEMA = {
    "prompt": {"type": str, "required": True},
    "max_tokens": {"type": int, "required": False, "default": 100},
    "temperature": {
        "type": float,
        "required": False,
        "default": 0.7,
        "constraints": lambda x: 0 <= x <= 2,
    },
}

def handler(job):
    result = validate(job["input"], INPUT_SCHEMA)
    if "errors" in result:
        return {"error": result["errors"]}

    validated = result["validated_input"]
    # process with validated input...
    return {"output": "done"}

Local Development

Test with JSON Input

# Using CLI argument
python handler.py --test_input '{"input": {"prompt": "hello"}}'

# Using test_input.json file (auto-detected)
echo '{"input": {"prompt": "hello"}}' > test_input.json
python handler.py

Running Tests

# Run all tests
python -m pytest

# Run a single test file
python -m pytest tests/test_api.py

# Run a specific test
python -m pytest tests/test_api.py::TestClient::test_run_success -v

FastAPI Development Server

python handler.py --waverless_serve_api --waverless_api_port 8000

Then use the interactive Swagger UI at http://localhost:8000/ or make requests:

# Synchronous execution
curl -X POST http://localhost:8000/runsync \
  -H "Content-Type: application/json" \
  -d '{"input": {"prompt": "hello"}}'

# Async execution
curl -X POST http://localhost:8000/run \
  -H "Content-Type: application/json" \
  -d '{"input": {"prompt": "hello"}}'

CLI Options

Option Description
--test_input JSON Run locally with JSON test input
--waverless_serve_api Start FastAPI development server
--waverless_api_host HOST API server host (default: localhost)
--waverless_api_port PORT API server port (default: 8000)
--waverless_log_level LEVEL Log level (DEBUG, INFO, WARN, ERROR)

Environment Variables

API Client

Variable Description
WAVESPEED_API_KEY WaveSpeed API key

Serverless Worker

Variable Description
WAVERLESS_POD_ID Worker/pod identifier
WAVERLESS_API_KEY API authentication key
WAVERLESS_WEBHOOK_GET_JOB Job fetch endpoint
WAVERLESS_WEBHOOK_POST_OUTPUT Result submission endpoint

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

wavespeed-0.1.1.tar.gz (61.0 kB view details)

Uploaded Source

Built Distribution

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

wavespeed-0.1.1-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

File details

Details for the file wavespeed-0.1.1.tar.gz.

File metadata

  • Download URL: wavespeed-0.1.1.tar.gz
  • Upload date:
  • Size: 61.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wavespeed-0.1.1.tar.gz
Algorithm Hash digest
SHA256 37e2fd683723f301d82f98e0495c153224ae3b718fed88e0299e56d5609fd1ce
MD5 b66eb7dc8c92f7a13b45da54a8ca9312
BLAKE2b-256 5ccea3d339b8333a5a6f7328f2078d0fdaf6fafe6248e62d12fc74e899aca137

See more details on using hashes here.

Provenance

The following attestation bundles were made for wavespeed-0.1.1.tar.gz:

Publisher: python-publish.yml on WaveSpeedAI/wavespeed-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 wavespeed-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: wavespeed-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wavespeed-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1698f689b6cc39bfdddf326ead1727112006ccc4b5899ebe7f1faa3b90701730
MD5 30d846ede3e9e20b6568f0450b818392
BLAKE2b-256 6c4b65d0a6e716eceff0bca6ef7782d79efd397e273157735e80942d458c7976

See more details on using hashes here.

Provenance

The following attestation bundles were made for wavespeed-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on WaveSpeedAI/wavespeed-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