{"id":21980044,"url":"https://github.com/parafoxia/xsync","last_synced_at":"2025-08-01T19:05:32.397Z","repository":{"id":42188512,"uuid":"478167379","full_name":"parafoxia/Xsync","owner":"parafoxia","description":"A set of tools to create hybrid sync/async interfaces.","archived":false,"fork":false,"pushed_at":"2022-04-11T13:07:47.000Z","size":61,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T15:44:55.786Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/xsync/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parafoxia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-05T14:31:42.000Z","updated_at":"2024-05-05T12:11:13.000Z","dependencies_parsed_at":"2022-08-12T08:51:05.673Z","dependency_job_id":null,"html_url":"https://github.com/parafoxia/Xsync","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/parafoxia/Xsync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parafoxia%2FXsync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parafoxia%2FXsync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parafoxia%2FXsync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parafoxia%2FXsync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parafoxia","download_url":"https://codeload.github.com/parafoxia/Xsync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parafoxia%2FXsync/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268281821,"owners_count":24225159,"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-08-01T02:00:08.611Z","response_time":67,"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-11-29T17:09:23.663Z","updated_at":"2025-08-01T19:05:32.328Z","avatar_url":"https://github.com/parafoxia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Xsync\n\n[![PyPi version](https://img.shields.io/pypi/v/Xsync.svg)](https://pypi.python.org/pypi/Xsync/)\n[![PyPI - Status](https://img.shields.io/pypi/status/Xsync)](https://pypi.python.org/pypi/Xsync/)\n[![Downloads](https://pepy.tech/badge/Xsync)](https://pepy.tech/project/Xsync)\n[![GitHub last commit](https://img.shields.io/github/last-commit/parafoxia/Xsync)](https://github.com/parafoxia/Xsync)\n[![License](https://img.shields.io/github/license/parafoxia/Xsync.svg)](https://github.com/parafoxia/Xsync/blob/main/LICENSE)\n\n[![CI](https://github.com/parafoxia/Xsync/actions/workflows/ci.yml/badge.svg)](https://github.com/parafoxia/Xsync/actions/workflows/ci.yml)\n[![Maintainability](https://api.codeclimate.com/v1/badges/8819bdebb2d4aa8dfcb7/maintainability)](https://codeclimate.com/github/parafoxia/Xsync/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/8819bdebb2d4aa8dfcb7/test_coverage)](https://codeclimate.com/github/parafoxia/Xsync/test_coverage)\n\u003c!-- [![Read the Docs](https://img.shields.io/readthedocs/Xsync)](https://Xsync.readthedocs.io/en/latest/index.html) --\u003e\n\nA set of tools to create hybrid sync/async interfaces.\n\nCPython versions 3.7 through 3.11-dev and PyPy versions 3.7 through 3.9 are officially supported.\n\nWindows, MacOS, and Linux are all supported.\n\n## What does *Xsync* do?\n\n*Xsync* allows developers to create dynamic interfaces which can be run in sync or async contexts.\n\nIn simple terms, it makes this possible:\n\n```py\nresult = my_function()\nresult = await my_function()\n```\n\nHow neat is that?!\n\n## Usage\n\nThe above behaviour can be achieved with the `as_hybrid` decorator:\n\n```py\n@xsync.as_hybrid()\ndef my_function():\n    ...\n```\n\nThis sets `my_function` up as a \"hybrid callable\", which is capable of being run both synchronously and asynchronously.\nHowever, we also need to set an async implementation for `my_function` for it to work.\nWe can do this using the `set_async_impl` decorator:\n\n```py\n@xsync.set_async_impl(my_function)\nasync def my_async_function():\n    ...\n```\n\nDoing this tells *Xsync* to run this function instead of `my_function` when awaiting:\n\n```py\nmy_function()        # runs as normal\nawait my_function()  # calls `my_async_function` instead\n```\n\nDon't worry, `my_async_function` can still be run directly, as you'd expect.\n\nIt also works on methods, class methods, and static methods:\n\n```py\nclass MyClass:\n    @xsync.as_hybrid()\n    def my_method(self):\n        ...\n\n    @xsync.set_async_impl(my_method)\n    async def my_async_method(self):\n        ...\n\n    @classmethod\n    @xsync.as_hybrid()\n    def my_class_method(cls):\n        ...\n\n    @classmethod\n    @xsync.set_async_impl(my_class_method)\n    async def my_async_class_method(cls):\n        ...\n\n    @staticmethod\n    @xsync.as_hybrid()\n    def my_static_method(cls):\n        ...\n\n    @staticmethod\n    @xsync.set_async_impl(my_static_method)\n    async def my_async_static_method(cls):\n        ...\n```\n\n***\n\nThe above is the newer (and better) of two available implementations.\n\n\u003cdetails\u003e\n\u003csummary\u003eView the old implementation\u003c/summary\u003e\n\nThe above behaviour can be achieved with the `maybe_async` decorator:\n\n```py\n@xsync.maybe_async()\ndef my_function():\n    ...\n```\n\nThis sets `my_function` up as a \"hybrid callable\", which is capable of being run both synchronously and asynchronously.\nHowever, we also need to set an async implementation for `my_function` for it to work.\nWe can do this by creating another function of the same name, but with an `_async_` prefix:\n\n```py\nasync def _async_my_function():\n    ...\n```\n\n*Xsync* searches for a function with the name of the original function prefixed by `_async_` at runtime, and runs this instead when awaiting:\n\n```py\nmy_function()        # runs as normal\nawait my_function()  # calls `_async_my_function` instead\n```\n\nIt also works on methods and class methods:\n\n```py\nclass MyClass:\n    @xsync.maybe_async()\n    def my_method(self):\n        ...\n\n    async def _async_my_method(self):\n        ...\n\n    @classmethod\n    @xsync.maybe_async()\n    def my_class_method(cls):\n        ...\n\n    @classmethod\n    async def _async_my_class_method(cls):\n        ...\n```\n\n**This implementation does not work with static methods.**\n\u003c/details\u003e\n\n## Contributing\n\nContributions are very much welcome! To get started:\n\n* Familiarise yourself with the [code of conduct](https://github.com/parafoxia/Xsync/blob/main/CODE_OF_CONDUCT.md)\n* Have a look at the [contributing guide](https://github.com/parafoxia/Xsync/blob/main/CONTRIBUTING.md)\n\n## License\n\nThe *Xsync* module for Python is licensed under the [BSD 3-Clause License](https://github.com/parafoxia/Xsync/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparafoxia%2Fxsync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparafoxia%2Fxsync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparafoxia%2Fxsync/lists"}