Registry / type-stubs / types-aiofiles

types-aiofiles

JSON →
library25.1.0.20260518pypypi✓ verified 26d ago

types-aiofiles provides type stubs for the aiofiles library, enabling static type checkers like MyPy and Pyright to verify code that uses aiofiles. It is part of the typeshed project and is regularly updated, with version 25.1.0.20251011 aiming for aiofiles==25.1.*.

pip install types-aiofiles
INSTALL
IMPORT
SIG · TYPES-AIOFILES
T
types-aiofiles
type-stubspythonv25.1.0.20260518
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v25.1.0.20260518 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

aiofiles-stubs
import aiofiles_stubs
import aiofiles-stubs

This example demonstrates basic asynchronous file writing and reading using `aiofiles`. Ensure `aiofiles` is installed alongside `types-aiofiles` for runtime execution.

import asyncio import aiofiles async def main(): # Write to a file asynchronously async with aiofiles.open('example.txt', mode='w') as f: await f.write('Hello, aiofiles!\n') await f.write('This is an async file operation.') print('Wrote to example.txt') # Read from a file asynchronously async with aiofiles.open('example.txt', mode='r') as f: contents = await f.read() print(f'Read from example.txt:\n{contents}') # Clean up (optional) import aiofiles.os await aiofiles.os.remove('example.txt') print('Cleaned up example.txt') if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
gotchaStub versions are designed for specific runtime library versions (e.g., `types-aiofiles==25.1.0.20251011` for `aiofiles==25.1.*`). Mismatches can lead to incorrect type checking results or missed type errors.
fix
Align the version of `types-aiofiles` with the version of `aiofiles` you are using. The `types-aiofiles` PyPI page usually specifies the target `aiofiles` version.
affects: All versions, especially when `aiofiles` and `types-aiofiles` versions diverge significantly.
breakingThis package provides *only* type stubs (`.pyi` files) for `aiofiles`, not the runtime library itself. You still need to install `aiofiles` (`pip install aiofiles`) to use its functionality. Attempting to run code with only `types-aiofiles` installed will result in `ModuleNotFoundError` for `aiofiles`.
fix
Always install the `aiofiles` package in addition to `types-aiofiles` for runtime execution. `pip install aiofiles types-aiofiles`.
affects: All versions
gotchaDo not attempt to import symbols directly from `types-aiofiles` in your runtime code. It is purely for static type checking; all runtime imports should come from the `aiofiles` package (e.g., `import aiofiles`, `import aiofiles.os`).
fix
Ensure all `import` statements in your runnable code target the `aiofiles` package, not `types-aiofiles`.
affects: All versions
gotchaA known issue in `typeshed` (and thus `types-aiofiles`) involved `aiofiles.tempfile.NamedTemporaryFile.name` being incorrectly typed as `FileDescriptorOrPath` instead of `str`. While potentially fixed in newer stub versions, verify with your type checker if you encounter issues when accessing the `.name` attribute.
fix
Check the exact type revealed by your type checker (e.g., `reveal_type(f.name)` with MyPy). If incorrect, consider upgrading `types-aiofiles` and `aiofiles` to their latest compatible versions or casting the type if necessary.
affects: Potentially older versions of `types-aiofiles` and/or specific `aiofiles` versions.
Upgrade
Version history
25.1.0.20260518latest on PyPI · released May 18, 2026
Audit
Dependencies
aiofilesrequiredThis package provides typing stubs for the `aiofiles` runtime library. You must install `aiofiles` separately to use the actual asynchronous file I/O functionality.
Agent activity
26 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
types-aiofiles — pip install types-aiofiles · libregistry