An 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.
I 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.
Since 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.
The 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...
There 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.
pip install winloop
You 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 to compile this library on your own.
python setup.py build_ext --inplace
The uv package manager is the preferred method for testing winloop and it's author uses ruff and uv by default.
uv venv
uv pip install winloopIf your bilding and testing it from your own fork the following should work.
uv pip install -e .If your planning to setup.py build_ext commands you will need to install setuptools and cython
uv pip install cython setuptoolsIf you find any bugs with this library be sure to open up an issue in the issuetracker. The Winloop Contributors and the Owner when available will be happy try to help you figure out and diagnose your problems.
# Here's A small Example of using winloop when uvloop is not available to us
import sys
import aiohttp
async def main():
async with aiohttp.ClientSession("https://httpbin.org") as client:
async with client.get("/ip") as resp:
print(await resp.json())
if __name__ == "__main__":
if sys.platform in ('win32', 'cygwin', 'cli'):
from winloop import run
else:
# if we're on apple or linux do this instead
from uvloop import run
run(main())Alternatively, There's another way to do this involving a smaller resource called winuvloop which combines both uvloop and winloop together.
import aiohttp
import winuvloop
async def main():
async with aiohttp.ClientSession("https://httpbin.org") as client:
async with client.get("/ip") as resp:
print(await resp.json())
if __name__ == "__main__":
winuvloop.run(main())-
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)
-
My Presentation and Virtual Confrence Because I'm too busy to go to python conventions: https://www.youtube.com/watch?v=Cbb6trkKWXY
I put my heart and soul into this library ever since it began and any help is appreciated and means a lot to me, I have other things I wish to explore so every little bit helps. No matter what I go through in life, my heart is always here.
- Forking the library.
- Mirroring Winloop's improvements on uvloop's side.
- Reviewing pull requests.
- Fixing or editing workflows.
- Finding and editing spelling mistakes.
