Rustiter
Rust-inspired iterator utilities for Python. This library implements most of the functions from the Rust Iterator trait.
Why
I'm a big fan of chaining function calls, but Python's functional programming tools can be cumbersome. No one really wants to use the built-in map, filter, and reduce functions.
I previously experimented with simpleufcs, which allows for chainable function calls in Python.
This library offers an alternative: while it doesn't provide full UFCS (Uniform Function Call Syntax), it performs slightly better and brings many useful functions from Rust’s iterator design, such as take, flat_map, and more. If you're familiar with Rust and not too concerned about performance, you'll likely enjoy using this.
Installation
pip install rustiter
Example
Here are some commonly used functions:
from rustiter import rter
ret = (
rter(range(10))
.filter(lambda x: x % 2 == 0)
.map(lambda x: x + 1)
.take(3)
.collect()
)
assert ret == [1, 3, 5]
assert rter(range(10)).reduce(lambda x, y: x + y, 0) == 45
Additional Information: Every function includes a doctest to demonstrate its usage.
Mutability
The mutability of Python's iterator is not ideal. Therefore, I marked the mutability of the functions as follows:
[Mut]: The iterator may be modified after this operation. If there's not aretains = ..., the rest elements is undefined.[UnMut]: The iterator will not be modified.[Consume]: The iterator may be consumed after this operation. Note that this does not mean the iterator will become empty; there may still be elements in it. This means that you should not use this iterator again.
benchmark
Windows 11, python 3.12.7
| Name (time in ns) | Min | Max | Mean | StdDev | Median | IQR | Outliers | OPS (Kops/s) | Rounds | Iterations |
|---|---|---|---|---|---|---|---|---|---|---|
| test_normal | 524.9999 (1.0) | 26,137.4998 (1.0) | 600.2414 (1.0) | 247.7502 (1.0) | 575.0001 (1.0) | 37.5001 (1.0) | 2947;10025 | 1,665.9964 (1.0) | 169492 | 8 |
| test_rustiter | 1,399.9997 (2.67) | 251,400.0007 (9.62) | 1,669.7782 (2.78) | 2,722.4341 (10.99) | 1,599.9995 (2.78) | 100.0008 (2.67) | 107;1465 | 598.8819 (0.36) | 31646 | 1 |
Metadata
Release files for rustiter 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rustiter-0.2.0.tar.gz | 8.7 kB | Without provenance | Details for rustiter-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rustiter-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for rustiter-0.2.0-py3-none-any.whl |
Total release size: 17.7 kB
Release files / rustiter-0.2.0.tar.gz
| Download URL | rustiter-0.2.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f44dcee818d2395466b3d1fc2c6a3be2e0a2bea086d0e12d992c518163fcad5e
|
|
BLAKE2b-256 checksum How to use checksums |
8adec74e1ca58ad20d910451fd4458226834943840013527a2c94893b11ee89a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.4.25
|
Release files / rustiter-0.2.0-py3-none-any.whl
| Download URL | rustiter-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26019b3df51cfb91435a224516e5222c1567781e0197171d415e328bc5ecb088
|
|
BLAKE2b-256 checksum How to use checksums |
2698b9a0c8334003d48207a7b754442f9ed2d88d62990861b3e03e85cd978059
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.4.25
|
Security for rustiter 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.