The `iterators` library provides utility classes and functions for working with Python iterators. It includes features like adding timeouts to iterators and creating synchronous/asynchronous pipelines. The current version is 0.2.0, with an irregular release cadence as new utility features are added.
pip install iteratorsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates the `TimeoutIterator` class, which wraps an existing iterator to introduce a timeout mechanism. If the next item isn't available within the specified timeout, a sentinel value is returned instead of waiting indefinitely or raising an exception. The timeout can also be adjusted dynamically. While `IteratorPipe` is a newer feature (v0.2.0), the most explicit quickstart examples in the official README focus on `TimeoutIterator`.
Always pin to exact versions (e.g., `pip install iterators==0.2.0`) or review release notes carefully before upgrading minor versions.
Refer to the library's test suite on GitHub for `IteratorPipe` examples, and exercise caution as its API might be subject to change in future minor releases.
Install the library using pip: `pip install iterators`
Ensure the import statement is correct, typically `from iterators import TimeoutIterator` (assuming it's directly in the top-level package). Double-check the exact class name and module structure based on the library's documentation.
Pass an iterable (e.g., a list, a generator, or another iterator) to the `TimeoutIterator` constructor: `my_iterator = TimeoutIterator(my_data_source, timeout=5)`
Ensure that the input you are passing is a valid Python iterable (e.g., a list, tuple, set, string, or an object implementing the `__iter__` method). For example, `TimeoutIterator([1, 2, 3], timeout=5)` or `TimeoutIterator(range(10), timeout=5)`.
No dependency data recorded yet.