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 hostPREFECT_REDIS_MESSAGING_PASSWORD: Redis password
How It Works
- Queue-based: Your calls to
publish_data()are queued in memory (non-blocking) - Batched publishing: A background worker wakes up every second to process all queued messages
- Optimized payload: All messages are serialized into a single JSON array and published as one Redis message
- 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
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 prefect_tool_state-0.0.8.tar.gz.
File metadata
- Download URL: prefect_tool_state-0.0.8.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5311516a3aee402355ab08e8174d18f98cf3feec55efa41b3e381caa04fd5c59
|
|
| MD5 |
62e1d44bd856e12d66f3dd41ee6569b7
|
|
| BLAKE2b-256 |
2021dcf9f4de0249ad0f3916827ebf8b0b9bc3dc48d98894ddb32d2126bfc5b5
|
File details
Details for the file prefect_tool_state-0.0.8-py3-none-any.whl.
File metadata
- Download URL: prefect_tool_state-0.0.8-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cfb9745ceaa78ddad34afe333bfb6f4f18e5dd22797f53333d0a62511016be4
|
|
| MD5 |
db2496ee161b1a5065e803d9fcd9c49f
|
|
| BLAKE2b-256 |
d89ea01c0ca83e7ec868924911dd7be30c603d8df8737d5c4f6334737b466c2b
|