{"id":20560818,"url":"https://github.com/feluxe/aioexec","last_synced_at":"2025-04-14T14:10:50.568Z","repository":{"id":50187067,"uuid":"126933222","full_name":"feluxe/aioexec","owner":"feluxe","description":"asyncio executors, clean and simple.","archived":false,"fork":false,"pushed_at":"2023-11-25T05:52:17.000Z","size":223,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T03:06:55.619Z","etag":null,"topics":["asyncio","concurrent-futures","executor","process-pool","python","thread-pool"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feluxe.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}},"created_at":"2018-03-27T05:25:36.000Z","updated_at":"2024-02-21T13:27:42.000Z","dependencies_parsed_at":"2023-01-31T01:30:30.893Z","dependency_job_id":null,"html_url":"https://github.com/feluxe/aioexec","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feluxe%2Faioexec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feluxe%2Faioexec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feluxe%2Faioexec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feluxe%2Faioexec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feluxe","download_url":"https://codeload.github.com/feluxe/aioexec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248894939,"owners_count":21179152,"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":["asyncio","concurrent-futures","executor","process-pool","python","thread-pool"],"created_at":"2024-11-16T03:55:55.615Z","updated_at":"2025-04-14T14:10:50.538Z","avatar_url":"https://github.com/feluxe.png","language":"Python","readme":"# aioexec\n\n## Description\n\nAioexec is a simple, intuitive interface around the `concurrent.futures` package and asyncio's `loop.run_in_executor` method. Aioexec is leightweight, no dependencies and ~100 LOC.\n\n## Requirements\n\naioexec requires Python `\u003e= 3.7`\n\n## Install\n\n    pip install aioexec\n\nor\n\n    pipenv install aioexec\n\n## Usage\n\n**Without** `aioexec` you usually run an executor something like this:\n\n```python\nimport aysncio\nfrom concurrent.futures import ProcessPoolExecutor\n\n# ...\n\nloop = asyncio.get_event_loop()\n\nfoo = await loop.run_in_executor(\n    ProcessPoolExecutor(1), lambda: my_func(foo='baz')\n)\n```\n\n**With** `aioexec` you would do the same like this:\n\n```python\nfrom aioexec import Procs\n\n# ...\n\nfoo = await Procs(1).call(my_func, foo='baz')\n```\n\nYou can pass both `sync` and `async` functions to an executor:\n\n```python\n\ndef my_sync_func(foo):\n    return stuff(foo)\n\nasync def my_async_func(foo):\n    return await stuff(foo)\n\n\nfoo = await Procs(1).call(my_sync_func, foo='baz')\nfoo = await Procs(1).call(my_async_func, foo='baz')\n```\n\nYou can call a `batch` of functions in the same executor like this:\n\n```python\nimport asyncio\nfrom aioexec import Procs, Call\n\n# ...\n\nmy_values = await asyncio.gather(\n    *Procs(3).batch(\n        Call(my_func, foo='bar'),\n        Call(my_func, foo='baz'),\n        Call(my_func, foo='qux'),\n    )\n)\n```\n\nThis plays nicely with comprehensions:\n\n```python\nmy_values = await asyncio.gather(\n    *Procs(10).batch(\n        Call(my_func, foo=i) for i in range(0, 10)\n    )\n)\n```\n\nYou can also spawn a `pool` in a context and make multiple different calls with the same executor:\n\n```python\nwith Procs(10) as pool:\n\n    value_a = await pool.call(my_func, foo='baz')\n\n    value_b = await aio.gather(\n        *pool.batch(\n            Call(my_func, foo=i) for i in range(0, 10)\n        )\n    )\n\n    # etc...\n```\n\nThe examples from above work the same for `Threads`, e.g.:\n\n```python\nfrom aioexec import Threads\n\n# ...\n\nfoo = await Threads(1).call(my_func, foo='baz')\n\n```\n\nIf necessary, you can pass an event `loop` to the executors like this:\n\n```python\nfoo = await Threads(1, my_loop).call(my_func, foo='baz')\nfoo = await Procs(1, my_loop).call(my_func, foo='baz')\n```\n\n## Development / Testing\n\nClone the repo and install dev packages:\n\n    pipenv install --dev\n\nRun tests:\n\n    pipenv run python make.py test\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeluxe%2Faioexec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeluxe%2Faioexec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeluxe%2Faioexec/lists"}