{"id":26641426,"url":"https://github.com/very-generic-software/rusty-iterators-py","last_synced_at":"2025-04-10T20:54:39.342Z","repository":{"id":266528433,"uuid":"898588657","full_name":"Very-Generic-Software/rusty-iterators-py","owner":"Very-Generic-Software","description":"Light, lazy, fast and statically typed iterators. Inspired by Rust, built in Cython.","archived":false,"fork":false,"pushed_at":"2025-03-18T17:42:42.000Z","size":216,"stargazers_count":3,"open_issues_count":70,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T18:38:34.386Z","etag":null,"topics":["cython","iterators","python","rust"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Very-Generic-Software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-04T17:00:56.000Z","updated_at":"2025-03-18T17:42:45.000Z","dependencies_parsed_at":"2024-12-04T18:40:44.818Z","dependency_job_id":"6924b1e0-27be-44e1-9ee5-752f72cea8e5","html_url":"https://github.com/Very-Generic-Software/rusty-iterators-py","commit_stats":null,"previous_names":["uncommon-nickname/rusty-iterators","uncommon-nickname/rusty-iterators-py","very-generic-software/rusty-iterators-py"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Very-Generic-Software%2Frusty-iterators-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Very-Generic-Software%2Frusty-iterators-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Very-Generic-Software%2Frusty-iterators-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Very-Generic-Software%2Frusty-iterators-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Very-Generic-Software","download_url":"https://codeload.github.com/Very-Generic-Software/rusty-iterators-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248297897,"owners_count":21080312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cython","iterators","python","rust"],"created_at":"2025-03-24T18:28:39.973Z","updated_at":"2025-04-10T20:54:39.321Z","avatar_url":"https://github.com/Very-Generic-Software.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rusty iterators\n\nHave you ever worked with a script in `Python` and wondered, why you can't have fast, light, lazy and easy-to-use iterators just like in `Rust`? Don't worry, we've got you covered - `rusty-iterators` bring the same interface to `Python`! And all of that without taking any shortcuts:\n\n- Thanks to `Cython`, the performance is comparable with `itertools` and `stdlib`, but with friendly functional programming syntax!\n- No production dependencies!\n- Full support for modern static typing, compatible with `Python \u003e= 3.10`!\n- Basic support for async programming, with even more to come!\n\nProject heavily inspired by great `Rust` iterators and crates like `Rayon` and `Itertools`. Make sure to check them out as well!\n\n## 🛠 Local build and installation\n\nAs a build system and dependency manager we use [uv](https://docs.astral.sh/uv/getting-started/installation/). As a build backend we use `setuptools` with `cython`. We provide a simple `Makefile` for easier development command access. To install the development dependencies, you can run:\n\n```bash\nmake install\n```\n\nTo create a distributable package (`.whl`), run:\n\n```bash\nmake build\n```\n\nthis will generate the `C` code from cython files, compile them into the `.so` libraries and build the final package with type stubs. A new `dist/` directory will appear in the project root, where your distributable will be stored.\n\nTo install the built package for local testing:\n\n```bash\npip3 install dist/rusty_iterators-\u003cyour-build-version\u003e.whl\n```\n\n## Coding code of conduct\n\nAny contributions are welcome, but please adhere to our code of conduct.\n\n#### Conventional commits\n\nWe utilize [conventional commits](https://gist.github.com/qoomon/5dfcdf8eec66a051ecd85625518cfd13). We don't maintain a `changelog` manually. Squashed commits, keeping the correct convention should be more than enough to create a release summary.\n\n#### Linting and formatting\n\nAs a linter and formatter, we use [ruff](https://docs.astral.sh/ruff/). You can run it via:\n\n```bash\nmake lint\n```\n\nAll changes, should ship with proper format and no lint errors, which will be verified in CI.\n\n#### Static typing\n\nWe are huge advocates of statically typed Python and put a lot of effort into keeping the types as clean as possible. We also maintain the types static tests located in the `tests/types/` directory. All of the contributed code should be properly typed and make changes in the type stubs if needed. To check the types:\n\n```bash\nmake mypy\n```\n\n#### Testing\n\nAll changes should ship with proper tests. We support multiple `python` versions, so to ensure everything works on every version, you can run the test on all of the via `tox`:\n\n```bash\nmake tox\n```\n\nYou can also run the tests on your current version:\n\n```bash\nmake test\n```\n\n## Examples\n\nProject is still in development and we don't have any proper documentation, so for now you can check out some very simple examples. More complex code can be found in the `examples/` directory.\n\n#### Count all even numbers in the iterator\n\n```python\nfrom rusty_iterators import LIter\n\nresult = LIter.from_items(1, 2, 3, 4).filter(lambda x: x % 2 == 0).count()\n```\n\n#### Check if iterator is incremental\n\n```python\nfrom rusty_iterators import LIter\n\nresult = (\n        LIter.from_items(1, 2, 4, 3)\n        .moving_window(2)\n        .map(lambda pair: pair[0] \u003c= pair[1])\n        .all()\n)\n```\n\n#### Iterate with indices over all even numbers in the iterator\n\n```python\nfrom rusty_iterators import LIter\n\nit = LIter.from_items(1, 2, 3, 4).filter(lambda x: x % 2 == 0).enumerate()\n\nfor idx, value in it:\n        print(idx, value)\n```\n\n#### Get `n` items from cycle iterator\n\n```python\nfrom rusty_iterators import LIter\n\nresult = (\n        LIter.from_items(1, 2, 3, 4)\n        .map(lambda x: x**2)\n        .cycle()\n        .take(30)\n        .collect()\n)\n```\n\n#### Parse file line by line\n\n```python\nfrom rusty_iterators import LIter\n\nwith open(\"example.txt\", \"r\") as file:\n    result = (\n        LIter.from_it(file)\n        .map(lambda l: LIter.from_seq(l).filter(lambda c: c.isnumeric()).map(lambda c: int(c)).collect())\n        .collect()\n    )\n```\n\n#### Dispatch asyncio tasks and wait for their execution\n\n```python\nasync def fetch_data(url: str) -\u003e Optional[bytes]:\n        # Some blocking api call.\n        ...\n\nasync def wait_for_task[T](task: asyncio.Task[T]) -\u003e T:\n        return await task\n\ntasks = (\n    LIter.from_items(1, 2, 3)\n    .map(lambda num: f\"https://mywebsite/api/items/{num}\")\n    .map(lambda url: fetch_data(url))\n    .map(lambda crt: asyncio.create_task(crt))\n    .collect_into(tuple)\n)\n\nresults = await LIter.from_seq(tasks).as_async().amap(wait_for_task).acollect()\n```\n\n## Authors\n\n- [Wiktor Nowak](@uncommon-nickname)\n- [Dawid Sielużycki](@Leghart)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvery-generic-software%2Frusty-iterators-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvery-generic-software%2Frusty-iterators-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvery-generic-software%2Frusty-iterators-py/lists"}