bagof.paths.AsyncPath
Bases: PurePathMixin, BaseWrapper
The await version of :class:Path: the same methods, as coroutines.
The parts that only describe a path (name, parent, /) stay
plain; the parts that touch storage are awaited.
>>> import asyncio
>>> from bagof.paths import AsyncPath
>>> async def main() -> None:
... p = AsyncPath("/etc/hostname")
... if await p.exists():
... print(await p.read_text())
Methods:
is_junction
async
is_junction() -> bool
Whether the path is a junction (a Windows concept; else False).
open
async
open(mode: str = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> Any
Open the path and return an async file object.
Use it with async with / async for. The handle's reads and
writes are awaited directly on a native driver, or run in a worker
thread on a synchronous one.
read_text
async
read_text(encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> str
Read the whole file as text.
write_bytes
async
Write data to the file as bytes, replacing any content.
write_text
async
write_text(data: str, encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> int
Write data to the file as text, replacing any content.
glob
async
glob(pattern: str, *, case_sensitive: bool | None = None, recurse_symlinks: bool = False) -> AsyncIterator[Self]
Yield the paths matching pattern under this directory.
rglob
async
rglob(pattern: str, *, case_sensitive: bool | None = None, recurse_symlinks: bool = False) -> AsyncIterator[Self]
Like :meth:glob, recursively.
mkdir
async
Create a directory at the path.
touch
async
Create the file at the path, or update its modification time.
copy
async
Copy this file or directory to target; return the new path.
copy_into
async
copy_into(target_dir: Any, *, follow_symlinks: bool = True, preserve_metadata: bool = False) -> Self
Copy into target_dir, keeping this path's name.
walk
async
walk(top_down: bool = True, on_error: Callable | None = None, follow_symlinks: bool = False) -> AsyncIterator[tuple[Self, list[str], list[str]]]
Walk the tree, yielding (path, dirnames, filenames) per dir.
One directory per thread hop, so mutating dirnames in place to
prune the descent works exactly as it does on the sync wrapper. Note
that on_error runs in a worker thread.
A natively-async driver walks on its own coroutine surface; pruning
by editing dirnames is not propagated there, since the driver
produced the whole level before it was yielded.
chmod
async
Change the file mode and permission bits.
symlink_to
async
Make this path a symbolic link to target.
link_to
async
link_to(target: Any) -> None
Make target a hard link to this path.
.. deprecated::
link_to takes the reverse argument order of
:meth:hardlink_to and was removed from pathlib in Python
3.12. Prefer :meth:hardlink_to; this is kept, and synthesized
where the driver dropped it, only for backward compatibility.
download_to
async
Download the path's contents to a local destination.