{"id":13907945,"url":"https://github.com/sethmlarson/pycon-async-sync-poster","last_synced_at":"2025-10-28T18:48:19.274Z","repository":{"id":66168604,"uuid":"258871223","full_name":"sethmlarson/pycon-async-sync-poster","owner":"sethmlarson","description":"An example project which demonstrates how to use some new tools to more easily maintain a codebase that supports both async and synchronous I/O and multiple async libraries.","archived":false,"fork":false,"pushed_at":"2020-05-06T17:17:05.000Z","size":910,"stargazers_count":22,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T15:11:20.458Z","etag":null,"topics":["async","asyncio","curio","pycon2020","python","trio"],"latest_commit_sha":null,"homepage":"https://sethmlarson.dev","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sethmlarson.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":"2020-04-25T20:48:39.000Z","updated_at":"2023-09-23T10:17:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"37c41c92-309d-4658-b725-e1bc38a5e1e7","html_url":"https://github.com/sethmlarson/pycon-async-sync-poster","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"b5e193b964fd14bd7bac7bec4c945e0f643c22c2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sethmlarson/pycon-async-sync-poster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethmlarson%2Fpycon-async-sync-poster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethmlarson%2Fpycon-async-sync-poster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethmlarson%2Fpycon-async-sync-poster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethmlarson%2Fpycon-async-sync-poster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sethmlarson","download_url":"https://codeload.github.com/sethmlarson/pycon-async-sync-poster/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethmlarson%2Fpycon-async-sync-poster/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265553301,"owners_count":23787050,"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":["async","asyncio","curio","pycon2020","python","trio"],"created_at":"2024-08-06T23:02:20.387Z","updated_at":"2025-10-28T18:48:14.251Z","avatar_url":"https://github.com/sethmlarson.png","language":"Python","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# Designing Libraries for Async and Synchronous I/O\n\nAn example project which demonstrates how to use\nsome new tools to more easily maintain a codebase that supports\nboth async and synchronous I/O and multiple async libraries.\n\n## Meet the Tools\n\n- Supporting Sync and Async:\n    - [unasync](https://github.com/python-trio/unasync)\n- Supporting multiple Async libraries:\n    - [sniffio](https://github.com/python-trio/sniffio)\n    - [anyio](https://github.com/agronholm/anyio)\n\nThe library itself is a massive contrived example that doesn't do anything useful.\nThe important part is seeing the different libraries and constructions\nall working together!\n\n## How the Project is Structured\n\nThere are three different categories of code that\ngo into creating a project that supports sync, asyncio, trio, etc:\n\n#### Code that directly interacts with I/O APIs (sockets, threads, asyncio)\n\nCode that directly interacts with individual APIs that are different across\nthe sync, asyncio, and Trio live under `backends/`. The function `get_backend()`\ncan either return a `SyncBackend` which uses a threadpool for parallelism and\n`time.sleep` or return a flavor of `AsyncBackend` depending on which library\n`sniffio` detects.\n\n#### Code that needs to be async but doesn't directly interact with I/O APIs\n\nThis is where the bulk of your libraries public API code will probably live.\nTypically you will write structural code here which call into your `Backend`\ncode written above.\n\nYou want to try to fit as much of your API code here as you can so you can\nbenefit from `unasync` generating the synchronous half automatically. When\nwriting this code you'll have to keep in mind what the resulting generated\ncode will look like though.\n\n#### Code that doesn't have I/O\n\nCode that doesn't need to touch I/O at all like enums, dataclasses, helpers, etc.\nAlso things like importing your `AsyncAPI` and `SyncAPI` to make them\naccessible to users.\n\n## Interesting Places to Look\n\n- [`IS_ASYNC` detection of whether we're in `_async/` or `_sync/`](https://github.com/sethmlarson/pycon-async-sync-project/blob/master/sleepy/_async/client.py#L9)\n- [Lazily load the backend so `AsyncSleeper` can be used in the global scope](https://github.com/sethmlarson/pycon-async-sync-project/blob/master/sleepy/_async/client.py#L38)\n- [Backend Detection using Sniffio](https://github.com/sethmlarson/pycon-async-sync-project/blob/master/sleepy/backends/__init__.py#L13)\n- [Unasync called within `setup.py` to generate `_sync/` code on dist build](https://github.com/sethmlarson/pycon-async-sync-project/blob/master/setup.py#L12)\n\n## The Library in Action\n\n```python\nimport asyncio\nimport sleepy\n\n# === Asyncio ===\n\nsleeper = sleepy.AsyncSleeper()\n\nasync def main_asyncio():\n    await sleeper.sleep_a_lot(3)\n\nasyncio.run(main_asyncio())\n\n# === Trio ===\n# python -m pip install trio\n\nimport trio\n\nsleeper = sleepy.AsyncSleeper()\n\nasync def main_trio():\n    await sleeper.sleep_a_lot(10)  \n\ntrio.run(main_trio)\n\n# === Sync ===\n\nsleeper = sleepy.SyncSleeper()\n\ndef main_sync():\n    sleeper.sleep_a_lot(5) \n\nmain_sync()\n```\n\n## License\n\nCC0-1.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsethmlarson%2Fpycon-async-sync-poster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsethmlarson%2Fpycon-async-sync-poster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsethmlarson%2Fpycon-async-sync-poster/lists"}