Registry / data / iterators

iterators

JSON →
library0.2.0pypypi✓ verified 22d ago

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 iterators
INSTALL
IMPORT
SIG · ITERATORS
I
iterators
datapythonv0.2.0
Install
1.6s avg
Import
199ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.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.214s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.184s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

TimeoutIterator
from iterators import TimeoutIterator
IteratorPipe
from iterators import IteratorPipe

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`.

import time from iterators import TimeoutIterator def my_slow_iterator(): yield 1 time.sleep(0.6) # This sleep might cause a timeout yield 2 time.sleep(0.4) yield 3 print("--- Demonstrating TimeoutIterator ---") # Example 1: Basic iteration i = my_slow_iterator() it = TimeoutIterator(i) print(f"Next: {next(it)}") # Expected: 1 print(f"Next: {next(it)}") # Expected: 2 (if timeout not hit) print(f"Next: {next(it)}") # Expected: 3 try: next(it) except StopIteration: print("StopIteration: Iterator exhausted.") print("\n--- Demonstrating Timeout with Sentinel ---") i_timeout = my_slow_iterator() it_timeout = TimeoutIterator(i_timeout, timeout=0.5) print(f"Next (with timeout): {next(it_timeout)}") # Expected: 1 # The next call will likely hit the timeout if sleep is 0.6s and timeout 0.5s sentinel_value = next(it_timeout) if sentinel_value == it_timeout.get_sentinel(): print("Timeout occurred, sentinel value returned.") else: print(f"Next (after potential timeout): {sentinel_value}") # Continue to consume remaining items, potentially with adjusted timeout it_timeout.set_timeout(0.7) # Adjust timeout dynamically try: print(f"Next (after timeout reset): {next(it_timeout)}") print(f"Next (final item): {next(it_timeout)}") except StopIteration: print("StopIteration: Iterator exhausted after timeout handling.")
Debug
Known issues
gotchaAs a pre-1.0.0 library (currently v0.2.0), this package does not strictly adhere to Semantic Versioning where minor versions guarantee backward compatibility. Breaking changes might occur between minor releases (e.g., 0.1.x to 0.2.x).
fix
Always pin to exact versions (e.g., `pip install iterators==0.2.0`) or review release notes carefully before upgrading minor versions.
affects: <1.0.0
gotchaThe `IteratorPipe` class, introduced in v0.2.0, is mentioned in release notes but lacks detailed examples or a dedicated section in the main GitHub README. Users might need to consult the source code or tests for advanced usage patterns, indicating a less stable API or incomplete documentation at this stage.
fix
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.
affects: >=0.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'iterators'
The `iterators` library has not been installed in your Python environment.
fix
Install the library using pip: `pip install iterators`
AttributeError: module 'iterators' has no attribute 'TimeoutIterator'
You are trying to import or access `TimeoutIterator` from the `iterators` module, but the name is either misspelled, or the class/function might be nested within another submodule, or it might not exist in the installed version of the library.
fix
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.
TypeError: TimeoutIterator() missing 1 required positional argument: 'iterable'
The `TimeoutIterator` class requires an iterable object as its first argument but none was provided during instantiation.
fix
Pass an iterable (e.g., a list, a generator, or another iterator) to the `TimeoutIterator` constructor: `my_iterator = TimeoutIterator(my_data_source, timeout=5)`
TypeError: object is not iterable
The object you provided to a function or class within the `iterators` library (such as `TimeoutIterator`) that expects an iterable is not actually an iterable.
fix
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)`.
Upgrade
Version history
0.2.0latest on PyPI · released Jan 23, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Resources
iterators — pip install iterators · libregistry