Registry / database / iterproxy

iterproxy

JSON →
library0.3.1pypypi✓ verified 21d ago

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.

pip install iterproxy
INSTALL
IMPORT
SIG · ITERPROXY
I
iterproxy
databasepythonv0.3.1
Install
1.6s avg
Import
12ms
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.3.1 · 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.012s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

IterProxy
from iterproxy import IterProxy

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.

from iterproxy import IterProxy # Create an IterProxy from any iterable my_list = list(range(10)) proxy = IterProxy(my_list) # Access elements using ORM-like API print(f"First element: {proxy.one()}") # Output: First element: 0 print(f"Next three elements: {proxy.many(3)}") # Output: Next three elements: [1, 2, 3] # Skip elements and get subsequent ones # Note: This operates on the *remaining* elements after previous calls print(f"Skip 2, get next 2: {proxy.skip(2).many(2)}") # Output: Skip 2, get next 2: [6, 7] # Get all remaining elements print(f"All remaining elements: {proxy.all()}") # Output: All remaining elements: [8, 9] # Handle potentially empty results gracefully empty_proxy = IterProxy([]) print(f"One or none from empty: {empty_proxy.one_or_none()}") # Output: One or none from empty: None # Chaining filter operations def is_odd(x): return x % 2 == 1 def gte_5(x): return x >= 5 # Re-create proxy for fresh iteration proxy_for_filter = IterProxy(range(10)) filtered_items = proxy_for_filter.filter(is_odd).filter(gte_5).all() print(f"Filtered (odd and >=5): {filtered_items}") # Output: Filtered (odd and >=5): [5, 7, 9] # Multiple filter functions in one call (implicit AND logic) proxy_combined_filter = IterProxy(range(10)) combined_filtered_items = proxy_combined_filter.filter(is_odd, gte_5).all() print(f"Combined filter (odd and >=5): {combined_filtered_items}") # Output: Combined filter (odd and >=5): [5, 7, 9]
Debug
Known issues
gotchaIterProxy 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`.
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))`).
affects: 0.1.1+
gotchaCalling `.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.
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.
affects: 0.1.1+
gotchaWhen 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.
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.
affects: 0.1.1+
Errors
Common errors & fixes
AttributeError: 'list' object has no attribute 'one'
Developers attempt to use iterproxy methods like .one() directly on standard Python iterables (e.g., lists) without first wrapping them with the IterProxy class.
fix
from iterproxy import IterProxy
my_list = [1, 2, 3]
proxy = IterProxy(my_list)
result = proxy.one()
ValueError: Sequence contains no items
The `.one()` method was called on an `IterProxy` instance whose underlying iterable was empty, which `iterproxy` explicitly raises as an error in such cases.
fix
from iterproxy import IterProxy
proxy = IterProxy([])
result = proxy.one_or_none() # Use .one_or_none() to return None if the sequence is empty
NameError: name 'IterProxy' is not defined
The main `IterProxy` class, which is the primary entry point for the library, was used in the code without being explicitly imported from the `iterproxy` package.
fix
from iterproxy import IterProxy
proxy = IterProxy([1, 2, 3])
ModuleNotFoundError: No module named 'iterproxy'
The `iterproxy` library is not installed in the current Python environment or the active environment does not include it.
fix
pip install iterproxy
Upgrade
Version history
0.3.1latest on PyPI · released Nov 2, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
iterproxy — pip install iterproxy · libregistry