Skip to main content

Python SDK for Queueflow distributed task queue

Project description

QueueFlow SDK

Python SDK for the QueueFlow distributed task queue.

QueueFlow is a production-grade task queue built with Python, FastAPI, Redis, and PostgreSQL. It supports priority queues, retry with exponential backoff, dead letter queues, scheduled tasks, multi-tenant isolation, and real-time WebSocket updates.

Installation

pip install queueflow-sdk

Quick Start

from queueflow_sdk import QueueFlowClient

# Create a tenant and get an API key
tenant = QueueFlowClient.create_tenant("https://your-server.com", "Company Name")
key = QueueFlowClient.create_api_key("https://your-server.com", tenant.id)

# Initialize the client
qf = QueueFlowClient("https://your-server.com", key.key)

# Submit a task
task = qf.submit("send_email", payload = {
    "to": "user@example.com",
    "subject": "Hello from QueueFlow",
    "body": "This was sent via the SDK",
})
print(f"Task {task.id} status: {task.status}")

# Wait for completion
result = qf.wait_for(task.id)
print(result.status) # "completed"
print(result.max_results) # {"sent_to": "user@example.com", ...}

# Always close when done
qf.close()

Context Manager

with QueueFlowClient("https://your-server.com", "your-api-key") as qf:
    task = qf.submit("process_image", payload = {
        "image_url": "https://example.com/photo.jpg",
        "width": 400,
        "height": 300,
    })
    result = qf.wait_for(task.id)

All Operations

Task Management

# Submit with priority and delay
task = qf.submit(
    "send_email",
    payload={"to": "user@example.com"},
    priority=10,          # 1=low, 5=normal, 10=high, 20=critical
    max_retries=3,
    delay_seconds=60,     # Wait 60 seconds before processing
    callback_url="https://your-app.com/webhook",  # POST result on completion
)

# Get task status
task = qf.get_task("task-uuid-here")
print(task.status)        # "completed"
print(task.is_complete)   # True
print(task.is_failed)     # False

# List tasks with filtering
tasks, total = qf.list_tasks(status="completed", page=1, page_size=20)

# Cancel a pending task
cancelled = qf.cancel("task-uuid-here")

# Retry a failed task
retried = qf.retry("task-uuid-here")

# Block until a task finishes
result = qf.wait_for("task-uuid-here", poll_interval=1.0, timeout=300)

Dead Letter Queue

# List dead tasks
dead_tasks = qf.list_dlq()

# Retry all dead tasks
qf.retry_all_dlq()

# Purge the DLQ (cannot be undone)
qf.purge_dlq()

Error Handling

from queueflow_sdk import (
    QueueFlowClient,
    AuthenticationError,
    NotFoundError,
    ConflictError,
    QueueFlowError,
)

qf = QueueFlowClient("https://your-server.com", "your-api-key")

try:
    qf.cancel("nonexistent-task-id")
except NotFoundError:
    print("Task not found")
except ConflictError:
    print("Task already completed — cannot cancel")
except AuthenticationError:
    print("Invalid API key")
except QueueFlowError as e:
    print(f"Error {e.status_code}: {e.message}")

Task Types

QueueFlow includes three built-in task handlers:

Task Name Payload Description
send_email to, subject, body Logs email or sends to a webhook
process_image image_url, width, height Downloads and resizes an image
generate_report report_type Generates a task summary report as PDF

Custom handlers can be added by registering functions with the @register decorator in the worker.

Links

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

queueflow_sdk-0.1.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

queueflow_sdk-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: queueflow_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for queueflow_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0dc65cbc02bf1d1ca36f3d6183d275a5cb7904607c361fcc2ffd257dc3f935a6
MD5 dc132d87f78662168804fd774297e9be
BLAKE2b-256 b86f18f11a91674db5fb51729858d4916e49ce1ce20bbc37f9fca042ff55ae1c

See more details on using hashes here.

File details

Details for the file queueflow_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: queueflow_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for queueflow_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 912af7e4b4100423acafc20dd20a7ec2d23f35504a2bfcf6cb8d1e0588debc0b
MD5 2fba7dc8925ba8b26f3ab4eaececbdd0
BLAKE2b-256 1f4bac149b80186641293b69c7a42b1648351f95537da7552ea87e36580131e3

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