Registry / http-networking / aiopath

aiopath

JSON →
library0.7.7pypypi✓ verified 85d ago

aiopath provides an asynchronous implementation of Python's standard `pathlib` module, enabling non-blocking file system operations within `asyncio`, `trio`, and other `async`/`await` compatible frameworks. It mirrors `pathlib`'s API, making it familiar for users who need to perform I/O-bound tasks concurrently without blocking the event loop. The library is currently at version 0.7.7 and maintains an active development, addressing compatibility with newer Python versions and bug fixes.

pip install aiopath
INSTALL
IMPORT
SIG · AIOPATH
A
aiopath
http-networkingpythonv0.7.7
Install
2.0s avg
Import
479ms
Disk
18MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.11 · 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
glibc
py 3.10
✓ —
✓ 2.15s
py 3.11
✓ —
✓ 2.05s
py 3.12
✓ —
✓ 1.85s
py 3.13
✓ —
✓ 1.83s
py 3.9
✕ build_error
✓ 2.35s
18MB installed
● package 18MB
Code
Verified usage

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

AsyncPath
from aiopath import AsyncPath
This is the primary class for asynchronous path operations, mirroring `pathlib.Path`.

This quickstart demonstrates basic asynchronous file operations using `AsyncPath`, including creating a directory, writing text to a file, reading its content, checking its properties, and cleaning up the created files and directories.

import asyncio from aiopath import AsyncPath from pathlib import Path import os async def main(): # Ensure a directory for testing exists test_dir = AsyncPath("aiopath_test_dir") if await test_dir.exists(): await test_dir.rmdir() await test_dir.mkdir() file_path = test_dir / "my_async_file.txt" content = "Hello, async world!\nThis is a test." # Write text asynchronously await file_path.write_text(content) print(f"Wrote to {file_path.name}:") # Read text asynchronously read_content = await file_path.read_text() print(f"Read from {file_path.name}:\n---\n{read_content}--- ") # Check if file exists and is a file print(f"Does {file_path.name} exist? {await file_path.exists()}") print(f"Is {file_path.name} a file? {await file_path.is_file()}") # Clean up await file_path.unlink() await test_dir.rmdir() print(f"Cleaned up {file_path.name} and {test_dir.name}.") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingOlder `aiopath` versions (prior to 0.7.x) are incompatible with Python 3.11+ due to reliance on internal `pathlib` APIs that were removed, leading to `ImportError`.
fix
Upgrade `aiopath` to version `0.7.0` or higher to ensure compatibility with Python 3.11 and newer. For Python 3.12, version `0.7.6` or higher is recommended.
affects: <0.7.0
gotchaThe `AsyncPath.walk()` method, as of some versions, may incorrectly return a synchronous generator, causing a `TypeError` when used with `async for`.
fix
Check for updates to `aiopath` that fix `AsyncPath.walk()` to return an `AsyncGenerator`. If not fixed, consider implementing a custom async walk or using `AsyncPath.iterdir()` for recursive traversal.
affects: Potentially 0.7.x (reported in 0.7.7 context)
gotchaCalling asynchronous methods (e.g., `resolve()`, `exists()`, `read_text()`) on `AsyncPath` objects without `await` will result in a `RuntimeWarning` (coroutine '...' was never awaited) and the operation will not execute.
fix
Always prepend `await` to `AsyncPath` methods that perform I/O operations, such as `await my_path.exists()` or `await my_path.read_text()`.
affects: All versions
Errors
Common errors & fixes
ImportError: cannot import name '_NormalAccessor' from 'pathlib' (Python 3.11)
An older version of `aiopath` attempted to import a private internal class from `pathlib` that was removed in Python 3.11.
fix
Upgrade `aiopath` to the latest version using `pip install --upgrade aiopath`. Version `0.7.0` and newer are designed for Python 3.11+ compatibility.
TypeError: 'async for' requires an object with __aiter__ method, got generator
This error occurs when attempting to use `async for` with `AsyncPath.walk()`, indicating that the method returned a regular (synchronous) generator instead of an asynchronous one.
fix
Verify your `aiopath` version. If the issue persists, manually iterate using `AsyncPath.iterdir()` and `is_dir()` for a recursive async walk, or await an official fix/workaround for `AsyncPath.walk()` in the library.
RuntimeWarning: coroutine '...' was never awaited
You called an asynchronous method on an `AsyncPath` object (e.g., `my_path.exists()`) but forgot to `await` its result.
fix
Ensure all I/O-performing methods of `AsyncPath` are properly `await`ed, like `await my_path.exists()` or `await my_path.resolve()`.
Upgrade
Version history
0.7.7latest on PyPI · released Oct 16, 2023
Audit
Dependencies
aiofilerequiredProvides asynchronous file I/O backend.
anyiorequiredProvides a consistent async I/O interface across different event loops.
typing-extensionsoptionalFor type hints on Python versions prior to 3.10.
Agent activity
53 hits · last 30 days
node
47
OpenAI (training)
1
Resources
aiopath — pip install aiopath · libregistry