Asynchronous local file access for Python asyncio apps
open sourceApache-2.0free
aiofiles is a Python library that gives asyncio applications asynchronous versions of local files, so reading and writing a file doesn't block the event loop. Its aiofiles.open() mirrors the built-in open() and hands each blocking operation to a thread pool. It also has async interfaces to the tempfile module and to pathlib.Path, and supports async iteration over a file's lines.
Problems it solves
- reading files in my asyncio web server blocks every other request
- write logs and uploads to disk from async Python code without stalling the event loop
- use pathlib-style file operations with await in an async app
Features
- aiofiles.open() with an API like the built-in open()
- buffered and unbuffered binary files and buffered text files
- async iteration over lines
- async tempfile interface
- async pathlib.Path
Limitations
- Works by handing each file operation to a thread pool, not through native asynchronous file I/O.1
