Skip to main content

A high-throughput progress publisher for Prefect tools with optimized batching

Project description

Prefect Tool State

A high-throughput tool state publisher for Prefect tools with optimized batching capabilities.

Features

  • High-frequency publishing: Optimized for scenarios where tool state updates are sent after each file is processed
  • Batch optimization: Collects messages over 1-second intervals and publishes them as a single JSON array
  • Background worker: Non-blocking interface with async background processing
  • Thread-safe: Safe to use from multiple threads
  • Automatic resource management: Handles Redis connection lifecycle automatically

Installation

pip install prefect-tool-state

Quick Start

# Quick Start updated for state publisher
from prefect_tool_state import get_tool_state_publisher, ToolStatePublisher, ToolState

# Get the global state publisher instance
publisher = get_tool_state_publisher()

# Publish tool state updates (non-blocking)
state_publisher = get_tool_state_publisher()
tool_state = ToolState(
    tool_run_id="tool-123",
    status="processing",
    current_file="example.txt",
    # ... other fields
)
state_publisher.publish_data(tool_state)

Configuration

The publisher requires Redis messaging environment variables:

  • PREFECT_REDIS_MESSAGING_HOST: Redis host
  • PREFECT_REDIS_MESSAGING_PASSWORD: Redis password

How It Works

  1. Queue-based: Your calls to publish_data() are queued in memory (non-blocking)
  2. Batched publishing: A background worker wakes up every second to process all queued messages
  3. Optimized payload: All messages are serialized into a single JSON array and published as one Redis message
  4. Consumer compatibility: The consumer must handle the batch format (array of tool states)

Performance

  • Before: 1000 file updates = 1000 Redis operations
  • After: 1000 file updates = 1 Redis operation per second
  • Latency: Sub-millisecond for publish_data() calls
  • Throughput: Handles thousands of updates per second

License

MIT License

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

prefect_tool_state-0.0.6.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

prefect_tool_state-0.0.6-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file prefect_tool_state-0.0.6.tar.gz.

File metadata

  • Download URL: prefect_tool_state-0.0.6.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for prefect_tool_state-0.0.6.tar.gz
Algorithm Hash digest
SHA256 8c7a08aa3742028f83b2190ba47e503f46c559a44e404831d9db8f5f86f7d2a5
MD5 c31e8c38a4aebc241e59c96a00de7ea3
BLAKE2b-256 1a7575c50a11b13f13fce434f9b05539a4c4412849bf9a1d50b7fcf45cd063cc

See more details on using hashes here.

File details

Details for the file prefect_tool_state-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for prefect_tool_state-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 044364eb3457b77f8149c03dd406d95b31a1a39c5465c687a5dfa87cb586f9cc
MD5 c1ffeba9e0ebd2faf1180524ed7306e2
BLAKE2b-256 877616043e06fe853610430ae64a3ba2f8ccd4a8179fee2c33334f1ff762aee9

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