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-aiofilesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic asynchronous file writing and reading using `aiofiles`. Ensure `aiofiles` is installed alongside `types-aiofiles` for runtime execution.
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.
Always install the `aiofiles` package in addition to `types-aiofiles` for runtime execution. `pip install aiofiles types-aiofiles`.
Ensure all `import` statements in your runnable code target the `aiofiles` package, not `types-aiofiles`.
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.