{"id":4965,"library":"iterproxy","title":"IterProxy: Extended Iterable API","description":"iterproxy is a Python library that enhances any iterable object with a convenient API, allowing access patterns commonly found in ORM frameworks. It provides methods like `.one()`, `.one_or_none()`, `.many(k)`, `.skip(k)`, and `.all()`. The current version is 0.3.1, released on November 2, 2023, indicating an active but infrequent release cadence.","status":"active","version":"0.3.1","language":"en","source_language":"en","source_url":"https://github.com/MacHu-GWU/iterproxy-project","tags":["iterator","iterable","proxy","utility","fluent-api","functional-programming"],"install":[{"cmd":"pip install iterproxy","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"IterProxy","correct":"from iterproxy import IterProxy"}],"quickstart":{"code":"from iterproxy import IterProxy\n\n# Create an IterProxy from any iterable\nmy_list = list(range(10))\nproxy = IterProxy(my_list)\n\n# Access elements using ORM-like API\nprint(f\"First element: {proxy.one()}\") # Output: First element: 0\nprint(f\"Next three elements: {proxy.many(3)}\") # Output: Next three elements: [1, 2, 3]\n\n# Skip elements and get subsequent ones\n# Note: This operates on the *remaining* elements after previous calls\nprint(f\"Skip 2, get next 2: {proxy.skip(2).many(2)}\") # Output: Skip 2, get next 2: [6, 7]\n\n# Get all remaining elements\nprint(f\"All remaining elements: {proxy.all()}\") # Output: All remaining elements: [8, 9]\n\n# Handle potentially empty results gracefully\nempty_proxy = IterProxy([])\nprint(f\"One or none from empty: {empty_proxy.one_or_none()}\") # Output: One or none from empty: None\n\n# Chaining filter operations\ndef is_odd(x): return x % 2 == 1\ndef gte_5(x): return x >= 5\n\n# Re-create proxy for fresh iteration\nproxy_for_filter = IterProxy(range(10))\nfiltered_items = proxy_for_filter.filter(is_odd).filter(gte_5).all()\nprint(f\"Filtered (odd and >=5): {filtered_items}\") # Output: Filtered (odd and >=5): [5, 7, 9]\n\n# Multiple filter functions in one call (implicit AND logic)\nproxy_combined_filter = IterProxy(range(10))\ncombined_filtered_items = proxy_combined_filter.filter(is_odd, gte_5).all()\nprint(f\"Combined filter (odd and >=5): {combined_filtered_items}\") # Output: Combined filter (odd and >=5): [5, 7, 9]","lang":"python","description":"This example demonstrates how to wrap a standard Python iterable with `IterProxy` and use its extended API for accessing elements, including `.one()`, `.many()`, `.skip()`, `.all()`, and `.one_or_none()`. It also shows how to chain multiple filter operations or combine them in a single call."},"warnings":[{"fix":"If you need to re-process the original sequence from the beginning, re-create the `IterProxy` instance from the original iterable or a fresh copy of it (e.g., `IterProxy(list(original_data))`).","message":"IterProxy methods, like other Python iterators, consume elements from the underlying iterable. Subsequent calls to methods such as `.one()`, `.many()`, or `.all()` on the same `IterProxy` instance will continue from where the last operation left off. If the iterable is fully consumed, further calls will yield no results or raise `StopIteration`.","severity":"gotcha","affected_versions":"0.1.1+"},{"fix":"To gracefully handle cases where no element might be available, use `.one_or_none()` which returns `None` instead of raising `StopIteration` when the iterable is exhausted. Alternatively, wrap `.one()` calls in a `try-except StopIteration` block.","message":"Calling `.one()` on an `IterProxy` that is empty or has been fully consumed will raise a `StopIteration` error. This is standard Python iterator behavior but can be unexpected if not handled.","severity":"gotcha","affected_versions":"0.1.1+"},{"fix":"For `OR` logic or more complex boolean combinations, define a single custom filter function that encapsulates the desired logic, or chain multiple `.filter()` calls if each applies a simple `AND` that aligns with the intended logic.","message":"When using the `.filter()` method, passing multiple filter functions to a single `.filter()` call (e.g., `proxy.filter(func1, func2)`) applies them with an implicit logical `AND` operation. This means all functions must return `True` for an item to pass the filter. Users expecting an `OR` operation or more complex logic might encounter unexpected results.","severity":"gotcha","affected_versions":"0.1.1+"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}