{"id":25164481,"url":"https://github.com/vizonex/winloop","last_synced_at":"2026-01-19T21:02:52.535Z","repository":{"id":166576596,"uuid":"642079458","full_name":"Vizonex/Winloop","owner":"Vizonex","description":"An Alternative library for uvloop compatability with windows ","archived":false,"fork":false,"pushed_at":"2025-05-08T22:35:16.000Z","size":3885,"stargazers_count":144,"open_issues_count":7,"forks_count":10,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-08T23:31:13.109Z","etag":null,"topics":["asyncio","cython","libuv","windows","winloop"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/winloop","language":"Cython","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/Vizonex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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,"zenodo":null}},"created_at":"2023-05-17T19:20:22.000Z","updated_at":"2025-05-08T22:42:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"d5c7e6a5-2894-4879-afc9-59b9b040666c","html_url":"https://github.com/Vizonex/Winloop","commit_stats":null,"previous_names":["vizonex/winloop"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FWinloop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FWinloop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FWinloop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vizonex%2FWinloop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vizonex","download_url":"https://codeload.github.com/Vizonex/Winloop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535792,"owners_count":22087397,"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","cython","libuv","windows","winloop"],"created_at":"2025-02-09T04:32:22.202Z","updated_at":"2025-12-05T10:04:40.921Z","avatar_url":"https://github.com/Vizonex.png","language":"Cython","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://raw.githubusercontent.com/Vizonex/Winloop/main/winloop.png\" width=\"200px\"/\u003e\n\u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n\n\n# Winloop\n[![PyPI version](https://badge.fury.io/py/winloop.svg)](https://badge.fury.io/py/winloop)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/winloop)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![License: Apache-2.0](https://img.shields.io/badge/License-Apache-yellow.svg)](https://opensource.org/licenses/Apache-2-0)\n\nAn alternative library for uvloop compatibility with Windows because let's face it. Windows' Python asyncio standard library is garbage, especially when Windows Defender decides to eat half of your RAM.\nI never really liked the fact that I couldn't make anything run faster especially when you have fiber internet connections in place and you've done all the optimizations you could possibly think of. It always felt disappointing when `libuv` is available for Windows [but Windows was never compatible with uvloop.](https://github.com/MagicStack/uvloop/issues/14#issuecomment-575826367])\n\nSince nobody was willing to step in after so many years of waiting, I went ahead and downloaded the source code for uvloop and started modifying the source code to be Windows compatible by carefully removing and changing parts that were not made for Windows. Many hours of research went into making this library.\n\nThe differences with __uvloop__ is that forking has been fully disabled and some smaller API calls had to be changed, error handling has been carefully modified and subprocesses release the GIL instead of forking out...\n\nThere is a performance increase of about 5 times with Winloop compared to using the `WindowsSelectorEventLoopPolicy` and `WindowsProactorEventLoopPolicy` which have been known to trigger SSL problems in `Python 3.9`. Winloop is a very good replacement for solving those SSL problems as well. This library also has comparable performance to its brother uvloop.\n\n\n\n## How to install Winloop on your Windows Operating System\n\n```\npip install winloop\n```\n\nYou can also clone the repository and build the extension yourself by running the command below if you wish to use or build this library locally. Note that you will need Cython and The Visual C++ extensions\nto compile this library on your own.\n\n```\npython setup.py build_ext --inplace\n```\n\n## Reporting issues\n\nIf you find any bugs with this library be sure to open up an issue in the [issuetracker](https://github.com/Vizonex/Winloop/issues). Me and other contributors will be happy try to help you figure out and diagnose your problems.\n\n## Making pull requests\nWe encourage anyone to make pull-requests to Winloop, containing anything from spelling mistakes to vulnerability patches. Every little bit helps keep this library maintained and alive.\nMake sure that you are able to compile the library with the steps shown above. We plan to implement a nightly workflow to verify one's pull-request in the future.\n\n\n\n```python\ntry:\n    import aiohttp\n    import aiohttp.web\nexcept ImportError:\n    skip_tests = True\nelse:\n    skip_tests = False\n\nimport asyncio\nimport unittest\nimport weakref\nimport winloop\nimport sys\n\nclass TestAioHTTP(unittest.TestCase):\n    def __init__(self, methodName: str = \"test_aiohttp_basic_1\") -\u003e None:\n        super().__init__(methodName)\n\n\n    def setUp(self):\n        self.loop = asyncio.get_event_loop()\n\n    def test_aiohttp_basic_1(self):\n        PAYLOAD = '\u003ch1\u003eIt Works!\u003c/h1\u003e' * 10000\n\n        async def on_request(request):\n            return aiohttp.web.Response(text=PAYLOAD)\n\n        asyncio.set_event_loop(self.loop)\n        app = aiohttp.web.Application()\n        app.router.add_get('/', on_request)\n\n        runner = aiohttp.web.AppRunner(app)\n        self.loop.run_until_complete(runner.setup())\n        site = aiohttp.web.TCPSite(runner, '0.0.0.0', '10000')\n        self.loop.run_until_complete(site.start())\n        port = site._server.sockets[0].getsockname()[1]\n\n        async def test():\n            # Make sure we're using the correct event loop.\n            self.assertIs(asyncio.get_event_loop(), self.loop)\n\n            for addr in (('localhost', port),\n                         ('127.0.0.1', port)):\n                async with aiohttp.ClientSession() as client:\n                    async with client.get('http://{}:{}'.format(*addr)) as r:\n                        self.assertEqual(r.status, 200)\n                        result = await r.text()\n                        self.assertEqual(result, PAYLOAD)\n\n        self.loop.run_until_complete(test())\n        self.loop.run_until_complete(runner.cleanup())\n\n    def test_aiohttp_graceful_shutdown(self):\n        async def websocket_handler(request):\n            ws = aiohttp.web.WebSocketResponse()\n            await ws.prepare(request)\n            request.app['websockets'].add(ws)\n            try:\n                async for msg in ws:\n                    await ws.send_str(msg.data)\n            finally:\n                request.app['websockets'].discard(ws)\n            return ws\n\n        async def on_shutdown(app):\n            for ws in set(app['websockets']):\n                await ws.close(\n                    code=aiohttp.WSCloseCode.GOING_AWAY,\n                    message='Server shutdown')\n\n        asyncio.set_event_loop(self.loop)\n        app = aiohttp.web.Application()\n        app.router.add_get('/', websocket_handler)\n        app.on_shutdown.append(on_shutdown)\n        app['websockets'] = weakref.WeakSet()\n\n        runner = aiohttp.web.AppRunner(app)\n        self.loop.run_until_complete(runner.setup())\n        site = aiohttp.web.TCPSite(runner, '0.0.0.0', '10000')\n        self.loop.run_until_complete(site.start())\n        port = site._server.sockets[0].getsockname()[1]\n\n        async def client():\n            async with aiohttp.ClientSession() as client:\n                async with client.ws_connect(\n                        'http://127.0.0.1:{}'.format(port)) as ws:\n                    await ws.send_str(\"hello\")\n                    async for msg in ws:\n                        assert msg.data == \"hello\"\n\n        client_task = asyncio.ensure_future(client())\n\n        async def stop():\n            await asyncio.sleep(0.1)\n            try:\n                await asyncio.wait_for(runner.cleanup(), timeout=0.1)\n            except Exception as e:\n                print(e)\n            finally:\n                try:\n                    client_task.cancel()\n                    await client_task\n                except asyncio.CancelledError:\n                    pass\n\n        self.loop.run_until_complete(stop())\n\n\n\nif __name__ == \"__main__\":\n    # print(\"tesing without winloop\")\n    # asyncio.DefaultEventLoopPolicy = asyncio.WindowsSelectorEventLoopPolicy\n    # asyncio.DefaultEventLoopPolicy = asyncio.WindowsProactorEventLoopPolicy\n    unittest.main()\n    # Looks like winloop might be 3x faster than the Proctor Event Loop , THAT's A HUGE IMPROVEMENT!\n    print(\"testing again but with winloop enabled\")\n    winloop.install()\n    unittest.main()\n```\n\nThe benchmarks for the code above are as follows\n\n## Benchmarks\n\n### TCP Connections\n-------------------\n\n| Asyncio Event Loop Policy         | Time (in Seconds)     |\n|-----------------------------------|-----------------------|\n| WinLoopPolicy                     | 0.493s                |\n| WindowsProactorEventLoopPolicy    | 2.510s                |\n| WindowsSelectorEventLoopPolicy    | 2.723s                |\n\n\nThat's a massive increase and jump from just TCP alone! I'll be posting more benchmarks soon, as\nI modify more of the current test suites made by uvloop...\n\n\n## How to Use Winloop with Fastapi\n\nThis was a cool little script I put together just to make Fastapi that much faster to handle:\n\n```python\n\n# TODO this code example is deprecated\nfrom fastapi import FastAPI\nfrom fastapi.responses import HTMLResponse\nimport winloop\nimport uvicorn\nimport asyncio\nimport datetime\n\napp = FastAPI()\n\n@app.on_event(\"startup\")\ndef make_assertion():\n    # Check to make sure that we bypassed the original eventloop Policy....\n    assert isinstance(asyncio.get_event_loop_policy(), winloop.WinLoopPolicy)\n\n\n@app.get(\"/test\")\nasync def test_get_request():\n    return HTMLResponse(\"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eFAST API WORKS WITH WINLOOP!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\")\n\n\n# starllete will use asyncio.to_thread() so that this can remain asynchronous\n@app.get(\"/date\")\ndef test_dynamic_response():\n    return str(datetime.datetime.now())\n\n\n# Although tricky to pass and is not normal, it does in fact work...\nif __name__ == \"__main__\":\n    winloop.install()\n    # Winloop's eventlooppolicy will be passed to uvicorn after this point...\n    loop = asyncio.get_event_loop()\n    config = uvicorn.Config(app=app,port=10000,loop=loop)\n    server = uvicorn.Server(config)\n    asyncio.run(server.serve())\n```\n\n\n## How To Use Winloop When Uvloop is not available\n\n```python\n\n# Here's A small Example of using winloop when uvloop is not available to us\nimport sys\nimport aiohttp\nimport asyncio\n\nasync def main():\n    async with aiohttp.ClientSession(\"https://httpbin.org\") as client:\n        async with client.get(\"/ip\") as resp:\n            print(await resp.json())\n\nif __name__ == \"__main__\":\n    if sys.platform in ('win32', 'cygwin', 'cli'):\n        from winloop import run\n    else:\n        # if we're on apple or linux do this instead\n        from uvloop import run\n    run(main())\n  ```\n\n\n ## TODO-List\n- [ ] In Winloop 0.2.0 or before 2026 I would like to start planning to migrate to pytest so that things could be formatted a little better. \nA Migration Python script might be needed or looked into. \n\n- [ ] Update Fastapi Example to a more recent version of fastapi\n\n- [ ] Help Wanted. We're looking for other maintainers to help us.\n\n- [x] Nightly Builds And Test Suite Workflows for anyone wanting to use newer unreleased versions. (Done, it runs now)\n\n- [ ] Adding in the necessary hooks for pyinstaller to compile this fast library to executable code even though hooks have been known to inflate the size of the `.exe` files. This is because calling hidden-imports for all the `__init__.py` modules might annoy some developers. (Luckily I'm aware of this issue because I've been doing this myself...) [Update, This is now pending and I hope that it passes](https://github.com/pyinstaller/pyinstaller-hooks-contrib/pull/867) \n\n- [x] write a workflow for nightly builds if necessary for verification of pull requests.\n\n- [ ] Update benchmarks (They are old) can't believe I maintained this project for over a year now...\n\n## Videos\n- By me: https://www.youtube.com/watch?v=tz9RYJ6aBZ8  (I might make a tutorial on how to use and install winloop it for those who have reading problems)\n- My Presentation and Virtual Confrence: https://www.youtube.com/watch?v=Cbb6trkKWXY\n\n## Contributing\nI put my heart and soul into this library ever since it began and any help is apperciated and means a lot to me, I have other things I wish to explore so every little bit helps\n\n### How Can I contribute?\n- I make and branch and make edits and then I do a pull requests before I just step in and add something new.\nThis way you have time to review my additions, changes or feature beforehand.\n- Forking The library.\n- Fixing or editing workflows.\n- Finding and editing spelling mistakes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvizonex%2Fwinloop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvizonex%2Fwinloop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvizonex%2Fwinloop/lists"}