miniasync is a small library build on top of asyncio to faciliate running small portions of asynchronous code in an otherwise synchronous application
miniasync is a small library build on top of asyncio to faciliate running small portions of asynchronous code in an otherwise synchronous application.
A typical use case is an application which is build as a synchronous application, but at some point needs to make an http request to two different web services and await the results before continuing. In synchronous Python you’d have to do each request in turn - miniasync makes it easier to run both requests in parallel without having to write asyncio boilerplate code.
import aiofiles import miniasync async def get_file_content(filename): async with aiofiles.open(filename, mode='r') as f: return await f.read() results = miniasync.run( get_file_content('file1.txt'), get_file_content('file2.txt'), ) assert results == [ '<the content of file1.txt>', '<the content of file2.txt>' ]
See the documentation on readthedocs for more examples and API.
Copyright © 2018, Alice Heaton. Released under the LGPL 3 License
- Documentation fixes
- Documentation improvements
- Initial implementation: miniasync.run and miniasync.loop