{"id":424,"library":"aiofiles","title":"aiofiles","description":"aiofiles is a Python library that provides asynchronous file operations for asyncio applications, enabling non-blocking file I/O. The current version is 25.1.0, released on October 9, 2025. The library follows a regular release cadence, with updates approximately every few months.","status":"active","version":"25.1.0","language":"python","source_language":"en","source_url":"https://github.com/Tinche/aiofiles","tags":["asyncio","asynchronous","file I/O","Python 3.9+","aiofiles"],"install":[{"cmd":"pip install aiofiles","lang":"bash","label":"Install aiofiles"}],"dependencies":[{"reason":"aiofiles 25.1.0 switched to using the uv library for asynchronous file operations","package":"uv","optional":false}],"imports":[{"note":"Ensure to import 'open' from 'aiofiles' for asynchronous file operations","symbol":"open","correct":"from aiofiles import open"}],"quickstart":{"code":"import aiofiles\nimport asyncio\n\nasync def read_file():\n    async with aiofiles.open('example.txt', mode='r') as f:\n        contents = await f.read()\n        print(contents)\n\nasyncio.run(read_file())","lang":"python","description":"This example demonstrates how to asynchronously read a file using aiofiles. The 'open' function from aiofiles is used to open the file, and 'await' is used to read its contents without blocking the event loop."},"warnings":[{"fix":"Upgrade to Python 3.9 or later to continue using aiofiles.","message":"Python 3.8 support dropped in aiofiles 25.1.0","severity":"breaking","affected_versions":"25.1.0"},{"fix":"Always use 'async with' for asynchronous context management with aiofiles.","message":"Ensure to use 'async with' when working with aiofiles to avoid 'AttributeError: __enter__' errors","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the file specified in aiofiles.open() exists at the given path in the execution environment.","message":"FileNotFoundError: The specified file does not exist when using aiofiles.open().","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the file specified in `aiofiles.open()` (e.g., 'example.txt') exists in the directory where the script is being executed, or provide the full absolute path to the file.","message":"FileNotFoundError occurs when the specified file does not exist at the given path for aiofiles.open().","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T13:43:18.539Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install aiofiles`.","cause":"The `aiofiles` library is not installed in the Python environment where the code is being run.","error":"ModuleNotFoundError: No module named 'aiofiles'"},{"fix":"Ensure that `aiofiles.open()` is used within an `async` function and with the `async with` keyword: `async with aiofiles.open('filename', mode='r') as f:`.","cause":"This error typically occurs when attempting to use `aiofiles.open()` with a synchronous `with` statement instead of an asynchronous `async with` statement, as `aiofiles.open()` returns an asynchronous context manager.","error":"AttributeError: __enter__"},{"fix":"Always `await` calls to `aiofiles` functions and methods that return coroutines, such as `aiofiles.open()`, `file.read()`, `file.write()`, or `aiofiles.os.remove()`: `await file.read()` or `await aiofiles.os.remove('file.txt')`.","cause":"An asynchronous function (coroutine) from `aiofiles` was called, but its returned coroutine object was not explicitly `await`ed, meaning its execution was never scheduled or completed.","error":"RuntimeWarning: coroutine '...' was never awaited"},{"fix":"Import `os.path` separately for path-related operations, as it is synchronous and generally safe to use outside of `aiofiles.os`: `import os.path` and then `os.path.join(...)`.","cause":"Developers often try to access submodules or functions like `path` directly through `aiofiles.os` expecting it to mirror the entire standard `os` module, but `aiofiles.os` only provides asynchronous versions of some `os` functions directly.","error":"AttributeError: module 'aiofiles.os' has no attribute 'path'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":4.4,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":4.4,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.18,"mem_mb":5.4,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":5.4,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.4,"mem_mb":8.2,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.35,"mem_mb":8.2,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.4,"mem_mb":8.7,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.36,"mem_mb":8.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4.3,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4.3,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}