{"id":15893384,"url":"https://github.com/multimeric/asynchronize","last_synced_at":"2025-10-07T20:00:11.133Z","repository":{"id":57412129,"uuid":"164219436","full_name":"multimeric/Asynchronize","owner":"multimeric","description":"Python package for converting callback functions to asynchronous coroutines","archived":false,"fork":false,"pushed_at":"2019-11-16T06:29:30.000Z","size":17,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T10:37:32.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/multimeric.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":"2019-01-05T13:54:33.000Z","updated_at":"2025-04-28T12:33:42.000Z","dependencies_parsed_at":"2022-09-26T17:11:11.917Z","dependency_job_id":null,"html_url":"https://github.com/multimeric/Asynchronize","commit_stats":null,"previous_names":["tmiguelt/asynchronize"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/multimeric/Asynchronize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FAsynchronize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FAsynchronize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FAsynchronize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FAsynchronize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multimeric","download_url":"https://codeload.github.com/multimeric/Asynchronize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FAsynchronize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278838467,"owners_count":26054721,"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-07T02:00:06.786Z","response_time":59,"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":[],"created_at":"2024-10-06T08:10:20.744Z","updated_at":"2025-10-07T20:00:11.057Z","avatar_url":"https://github.com/multimeric.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Asynchronize\n## Introduction\nAsynchronize is designed for situations where you are using a library that provides a callback interface, but you want\nto work with the convenience of `await` or `async for`.\n\n## Installation\nTo install Asynchronize, run:\n```bash\npip install asynchronize\n```\n\n## Examples\n### Async Generator\nFirst, let's say you're working with a library that's designed to call `step_callback` each time it receives a new chunk of data, and then `end_callback` once it's finished.\n[`sounddevice.InputStream`](https://github.com/spatialaudio/python-sounddevice) works like this:\n```python\nlibrary = MultiThreadedLibrary(\n    step_callback=step_callback,\n    end_callback=end_callback\n)\n```\n\nWith [`sounddevice.InputStream`](https://github.com/spatialaudio/python-sounddevice), this looks like:\n```python\nimport sounddevice as sd\n\nsd.InputStream(\n    channels=2,\n    callback=step_callback,\n    finished_callback=finished_callback\n)\n```\n\nTo convert this library into an [async generator](https://www.python.org/dev/peps/pep-0525/) you can iterate with `async for`, all you need to do is instantiate `asynchronize.AsyncCallback`, and pass its methods into whatever is expecting the callbacks:\n```python\nimport asynchronize\n\ncallback = asynchronize.AsyncCallback()\nlib = MultiThreadedLibrary(\n    step_callback=callback.step_callback,\n    end_callback=callback.finished_callback,\n)\nlib.start()\n\nasync for val in callback:\n    # Do something with val\n    pass\n```\n\n### Awaitable Function\nThis time, let's assume that the library is designed to call a single callback once it's processed something, and after that it's done.\nFor example:\n```python\nlib = MultiThreadedLibrary(\n    callback=callback,\n)\n```\n\nTo convert this library into an awaitable, instantiate `asynchronize.AsyncCallback` as before, but this time you only need to pass in the `finished_callback`:\n```python\nimport asynchronize\n\ncallback = asynchronize.AsyncCallback()\nlib = MultiThreadedLibrary(\n    end_callback=callback.finished_callback\n)\nlib.start()\n\nval = await callback\n```\n\n### More Examples\nA more complicated, real-world example is available in [`example.py`](https://github.com/TMiguelT/Asynchronize/blob/master/example.py).\n\nIn addition, the unit tests can be a useful example on how to use the library, from end to end: [`test_general.py`](https://github.com/TMiguelT/Asynchronize/blob/master/test/test_general.py).\n\n## API\nAsynchronize is actually very simple.\nThe only public class is `asynchronize.AsyncCallback`, and its constructor has no arguments.\nThe only way to use the class is by passing `step_callback` or `finished_callback` to something that expects a callback.\nThat's all!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fasynchronize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultimeric%2Fasynchronize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fasynchronize/lists"}