A Python web framework for building APIs with standard type hints, offering automatic validation, OpenAPI docs and high performance.
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
Install aiofiles from PyPI
pip install aiofiles - 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
Python rate limiting library offering Fixed Window, Sliding Window, Token Bucket, Leaky Bucket and GCRA algorithms with Redis or in-memory storage.
A pure-Python utility library of 230+ extra constructs that extend the standard library, with no dependencies.
A pure Python, asynchronous wrapper for the Telegram Bot API, with high-level classes in telegram.ext for building bots.
Python HTTP client built on curl that can impersonate browser TLS, JA3, and HTTP/2 fingerprints to get past blocks.
A lightweight ASGI framework and toolkit for building async web services and APIs in Python.