skillfed

iterators

Iterator utility classes and functions

iterators v0.2.0 721.8K downloads/30d#5,229 on PyPI10
Permissive license DORMANT released

What it is and what it does

TimeoutIterator is a wrapper class that adds timeout semantics to any Python iterator. When you wrap an iterator with TimeoutIterator and call next() on it, the wrapper will wait for the underlying iterator to yield a value, but only up to a specified timeout duration. If the timeout expires before a value arrives, TimeoutIterator returns a sentinel object instead of blocking indefinitely or raising an exception.

The package supports both fixed timeouts (set once at construction) and dynamic timeout adjustment via set_timeout(). When a timeout occurs, iteration continues—the next call to next() will attempt to retrieve the next value from the underlying iterator with the current timeout setting. This is useful for scenarios where you're iterating over slow or potentially stalled sources and need to enforce a deadline without terminating the entire iteration.

Use it for:

  • Wrap a generator that fetches data from a slow source to enforce per-item timeout and skip items that take too long.
  • Protect against runaway generators in a data pipeline by returning a sentinel when iteration stalls beyond a threshold.
  • Dynamically adjust timeout thresholds during iteration based on observed latency or changing system conditions.
  • Iterate over file handles or network streams with a deadline, gracefully handling slow or hung sources.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Wraps Python iterators to add timeout behavior, returning a sentinel value when iteration takes longer than a specified duration.

Yes, if you need simple timeout semantics on synchronous iterators and can tolerate dormant maintenance. The package has no dependencies, low install friction, and a permissive license. However, verify that the timeout mechanism meets your concurrency and performance requirements before relying on it in production—the project has not been actively maintained since early 2023.

Install

iterators on PyPI

pip

pip install iterators

uv

uv add iterators

poetry

poetry add iterators

Installing iterators

Before you install

Low install friction with no runtime dependencies. Package is dormant—last release was 2023-01-23 with no commits since 2024-07-31—so expect no active maintenance or bug fixes.

License in practice

MIT license (permissive) means you can use, modify, and distribute this package freely with minimal restrictions.

Quickstart

from iterators import TimeoutIterator

def iter_with_sleep():
    yield 1
    yield 2

i = iter_with_sleep()
it = TimeoutIterator(i, timeout=0.5)
print(next(it))
print(next(it))

Requires Python 3.6 or later.

Verify before relying

  • Whether TimeoutIterator works correctly with generators that yield at unpredictable intervals or with very short timeout windows.
  • Whether the timeout mechanism is thread-safe or suitable for concurrent iteration scenarios.
  • Performance overhead of wrapping iterators, especially for high-frequency iteration patterns.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.6)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance dormant — 1,299 days since the last release
Last repo commit
First released
Downloads 721,807/month — #5,229 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: iterators-0.2.0-py3-none-any.whl

Keywords: ITERATOR, TIMEOUT, SYNC

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Software Development :: Libraries :: Python Modules

Tags

iterator timeout wrappertimeout for iteratorsiterator with timeoutiteration timeout controltimeout sentinel iteratoriterator deadline enforcementsync iterator timeout
iterator-controltimeout-wrapper

More Python Modules packages