Registry / workflow / wirerope

wirerope

JSON →
library1.0.0pypypi✓ verified 25d ago

Wirerope is a Python library that transforms functions and methods into fully controllable objects, enabling features like reentrant locks, timeouts, retries, and rate limits. Its current stable version is 1.0.0. After a period of rapid pre-1.0 development, the library has maintained a stable release cadence since its 1.0.0 release in December 2023.

pip install wirerope
INSTALL
IMPORT
SIG · WIREROPE
W
wirerope
workflowpythonv1.0.0
Install
1.6s avg
Import
42ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.042s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.042s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WireRope
from wirerope import WireRope

This quickstart demonstrates how to wrap a basic Python function with `WireRope` to gain control over its execution. It then shows more advanced usage with timeout functionality, where `WireRope` raises a `TimeoutError` if the wrapped function exceeds a specified duration, and how to configure automatic retries for flaky operations.

import time from wirerope import WireRope def my_function(x, y): print(f"Executing my_function with {x}, {y}") return x + y # Wrap a regular function rope_func = WireRope(my_function) result_func = rope_func.call(10, 20) print(f"Result from wrapped function: {result_func}") # Example with timeout control def long_task(): print("Long task started...") time.sleep(2) # Simulate work print("Long task finished.") return "Task Complete" # Set a timeout shorter than the task duration rope_timeout = WireRope(long_task, timeout=1) try: timeout_result = rope_timeout.call() print(f"Timeout Result: {timeout_result}") except TimeoutError: print("Task timed out as expected after 1 second.") # Example with retries def flaky_task(attempt): if attempt < 2: raise ValueError("Simulating a temporary failure") return "Success after retries" # WireRope automatically passes an 'attempt' argument to the wrapped function # when 'retries' is enabled. The first call is attempt=0. rope_retries = WireRope(flaky_task, retries=3) try: # The 'attempt' argument will be automatically injected by WireRope # Note: flaky_task would typically infer the attempt count internally or not use it directly # For this example, we demonstrate it expecting an 'attempt' parameter # In real world, your function might just fail and WireRope retries it result_retries = rope_retries.call(attempt=0) print(f"Result from retried task: {result_retries}") except Exception as e: print(f"Failed after retries: {e}")
Debug
Known issues
gotchaWhen using `timeout`, the underlying function or operation might continue running in the background even after `TimeoutError` is raised. `WireRope` interrupts the call from the caller's perspective, but does not inherently cancel or terminate the wrapped function's execution, especially for I/O-bound or native code. This can lead to resource leaks or unexpected side effects.
fix
Be aware of the wrapped function's behavior during a timeout. If true cancellation is required, the wrapped function itself must be designed to be cancelable (e.g., by checking a flag, using `asyncio.CancelledError`, or implementing specific resource cleanup).
affects: All versions
gotchaEmploying the `retries` feature without ensuring the wrapped function is idempotent or handles multiple executions gracefully can lead to unintended side effects. Each retry re-executes the function, potentially causing duplicate actions if the function isn't designed for it.
fix
Design the wrapped function to be idempotent (producing the same result and side effects regardless of how many times it's executed) or to explicitly handle retry attempts (e.g., by checking for existing data before performing an action).
affects: All versions
gotchaWhen wrapping class methods or functions that rely on specific contextual state, `WireRope` creates a new execution context. If the wrapped callable needs to access or modify external state (e.g., `self` attributes in a method), ensure `WireRope` is initialized with the correct `self` reference or that state is passed explicitly. Direct modification of `self` might not be reflected as expected without careful handling.
fix
For class methods, ensure `WireRope` is instantiated correctly within the class context or passed the `self` instance. For complex state management, consider passing necessary state explicitly as arguments to the wrapped function or using `wirerope.context` primitives if your use case aligns with its design for context propagation.
affects: All versions
Upgrade
Version history
1.0.0latest on PyPI · released Jan 16, 2025
Audit
Dependencies
py_expression_evalrequiredUsed for expression evaluation within internal logic, particularly for dynamic configurations.
Agent activity
49 hits · last 30 days
node
40
OpenAI (training)
2
Resources
wirerope — pip install wirerope · libregistry