{"id":31829533,"url":"https://github.com/leavers/fluentmap","last_synced_at":"2025-10-11T20:28:31.180Z","repository":{"id":253967030,"uuid":"778989894","full_name":"leavers/fluentmap","owner":"leavers","description":"A drop-in Python map replacement featuring parallel and batch processing","archived":false,"fork":false,"pushed_at":"2024-12-07T15:58:48.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-25T07:44:34.115Z","etag":null,"topics":["batch","chunk","functional-programming","mapreduce","parallel-processing","python"],"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/leavers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-03-28T20:16:08.000Z","updated_at":"2024-12-07T15:57:17.000Z","dependencies_parsed_at":"2024-08-20T17:01:51.980Z","dependency_job_id":"5c64d20d-d4ec-4bb3-903a-c26516eb3b7c","html_url":"https://github.com/leavers/fluentmap","commit_stats":null,"previous_names":["leavers/fluentmap"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/leavers/fluentmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavers%2Ffluentmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavers%2Ffluentmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavers%2Ffluentmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavers%2Ffluentmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leavers","download_url":"https://codeload.github.com/leavers/fluentmap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavers%2Ffluentmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008619,"owners_count":26084480,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["batch","chunk","functional-programming","mapreduce","parallel-processing","python"],"created_at":"2025-10-11T20:28:29.402Z","updated_at":"2025-10-11T20:28:31.175Z","avatar_url":"https://github.com/leavers.png","language":"Python","readme":"# Fluentmap\n\n[![Testing](https://github.com/leavers/fluentmap/actions/workflows/test-suite.yml/badge.svg)](https://github.com/leavers/fluentmap/actions/workflows/test-suite.yml)\n[![Package version](https://img.shields.io/pypi/v/fluentmap.svg)](https://pypi.org/project/fluentmap/)\n[![Python](https://img.shields.io/pypi/pyversions/fluentmap.svg)](https://pypi.org/project/fluentmap/)\n\nFluentmap provides a drop-in Python map replacement featuring parallel and batch\nprocessing.\n\n## Features\n\n- Use `executor` to run tasks in parallel.\n- Use `batch_size`/`chunk_size` to send parameters in batches/chunks.\n- Use `num_prepare` to prepare data in advance for better performance.\n- Call `on_return` hook to process the return value of each task.\n\n## Installation\n\nFluentmap is available on [PyPI](https://pypi.org/project/fluentmap/):\n\n```shell\npip install fluentmap\n```\n\n## Usage\n\n### Drop-in replacement\n\nYou can start to use fluentmap just like built-in `map`:\n\n```python\nfrom typing import Any, List\n\nfrom fluentmap import map\n\n\nitems: List[str] = [...]\n\n\ndef heavy_task(item: str) -\u003e Any:\n    \"\"\"Suppose this function represents a computationally expensive task.\"\"\"\n\n\ndef postprocessing(result: Any):\n    \"\"\"Suppose this function represents a postprocessing task.\"\"\"\n\n\nfor result in map(heavy_task, items):\n    postprocessing(result)\n```\n\n### Parallel processing\n\nAs `heavy_task` is a computationally expensive task, you can use `executor` to\nrun it in parallel.\n\n```python\nfrom concurrent.futures import ProcessPoolExecutor\n\nfrom fluentmap import map\n\n# ......\n\nwith ProcessPoolExecutor() as executor:\n    # each heavy_task invocation runs in a separate process\n    for result in map(heavy_task, items, executor=executor):\n        postprocessing(result)\n```\n\n### Batch/chunk processing\n\nYou can use `batch_size`/`chunk_size` to send arguments in batches/chunks.\n\nThe difference between them is that `batch_size` packs multiple arguments into a batch\nbefore sending them to the function, therefore the function needs to be modified to\nhandle a list of arguments.\n\nOn the other hand, `chunk_size` packs multiple arguments into a chunks before passing\nthem to executor workers, while workers still process each argument sequentially.\n\n```python\nfrom concurrent.futures import ProcessPoolExecutor\nfrom typing import Any, List\n\nfrom fluentmap import map\n\n\n# ......\n\n\ndef heavy_task_in_batch(item: List[str]) -\u003e Any:\n    \"\"\"Note that `item` is a list since when `batch_size` is set,\n    fluentmap will concatenate multiple items into a batch before sending them to\n    the function which is to be invoked.\n    \"\"\"\n\n\n# An example of using `batch_size`\nwith ProcessPoolExecutor() as executor:\n    for result in map(\n        heavy_task_in_batch,\n        items,\n        executor=executor,\n        batch_size=64,\n    ):\n        postprocessing(result)\n\n# An example of using `chunk_size` \nwith ProcessPoolExecutor() as executor:\n    for result in map(\n        heavy_task,\n        items,\n        executor=executor,\n        chunk_size=32,\n    ):\n        postprocessing(result)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleavers%2Ffluentmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleavers%2Ffluentmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleavers%2Ffluentmap/lists"}