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 wireropeVerified import paths — ran on the pinned version, not inferred.
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.
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).
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).
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.