Repolode
Tinche

Tinche/aiofiles

An asyncio-compatible library that wraps blocking local file IO, os, tempfile and pathlib operations so they run in a thread pool without stalling the event loop.

Stars
3,270
Forks
182
Open issues
66
Last commit
4 days ago

What is it?

aiofiles is a Python library for reading and writing local files inside asyncio applications. Ordinary file IO blocks the executing thread, which can stall an event loop. aiofiles provides asynchronous file objects whose methods such as read, write and seek are coroutines that delegate the actual work to a thread pool executor.

The API closely mirrors the built-in open(), so existing code is easy to convert, and async for works for line iteration. The package also includes async wrappers for the tempfile module, the os functions that operate on files and directories, and a pathlib.Path replacement whose filesystem methods are awaitable.

Install it with pip install aiofiles. The project is licensed under Apache-2.0 and its tests run with tox.

Key features

  • 01Async file objects with an API similar to the built-in open()
  • 02Blocking file operations run in a thread pool executor
  • 03Async iteration over file lines with async for
  • 04Async wrappers for tempfile and common os file functions
  • 05Async pathlib.Path with awaitable filesystem methods

Use cases

  • Reading or writing log and data files in an asyncio web server without blocking requests
  • Creating temporary files or directories inside async tasks
  • Walking directory trees asynchronously with pathlib-style calls

Quick start

  1. 1

    Install aiofiles from PyPI

    pip install aiofiles
  2. 2

    Open a file asynchronously with aiofiles.open and await reads

Things to know

  • File operations run in a thread pool, so they are not truly non-blocking at the OS level.

Topics

FAQ

What is aiofiles?
An asyncio-compatible library that wraps blocking local file IO, os, tempfile and pathlib operations so they run in a thread pool without stalling the event loop. aiofiles is a Python library for reading and writing local files inside asyncio applications. Ordinary file IO blocks the executing thread, which can stall an event loop. aiofiles provides asynchronous file objects whose methods such as read, write and seek are coroutines that delegate the actual work to a thread pool executor.
Is aiofiles free to use? What license does it have?
aiofiles is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is aiofiles still maintained?
Actively maintained. The last commit to aiofiles was on Oct 21, 2026.
What can I use aiofiles for?
Reading or writing log and data files in an asyncio web server without blocking requests Creating temporary files or directories inside async tasks Walking directory trees asynchronously with pathlib-style calls
How do I install aiofiles?
Install aiofiles from PyPI: pip install aiofiles Open a file asynchronously with aiofiles.open and await reads
Where can I get aiofiles?
The source code and installation instructions are on GitHub: https://github.com/Tinche/aiofiles

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects