aiomegfile.smart module
- async aiomegfile.smart.smart_abspath(path: str | PathLike) str[source]
Return the absolute path of the given path.
- Parameters:
path – Given path.
- Returns:
Absolute path string.
- Return type:
str
- async aiomegfile.smart.smart_concat(src_paths: List[str | PathLike], dst_path: str | PathLike) None[source]
Concatenate files in src_paths into a single file at dst_path.
- Parameters:
src_paths – List of source file paths to concatenate.
dst_path – Destination path for the concatenated file.
- async aiomegfile.smart.smart_copy(src_path: str | PathLike, dst_path: str | PathLike, *, followlinks: bool = False) str[source]
Copy a file or directory and return the destination path string.
- Parameters:
src_path – Source path to copy.
dst_path – Destination path.
followlinks – Whether to follow symbolic links.
- Returns:
Destination path string.
- Return type:
str
- async aiomegfile.smart.smart_exists(path: str | PathLike, *, followlinks: bool = False) bool[source]
Return whether the path points to an existing file or directory.
- Parameters:
path – Path to check.
followlinks – Whether to follow symbolic links.
- Returns:
True if the path exists, otherwise False.
- async aiomegfile.smart.smart_glob(path: str | PathLike, *, recursive: bool = True) List[str][source]
Return paths whose paths match the glob pattern.
- Parameters:
path – Base path to search under.
recursive – If False,
**will not search directory recursively.
- Returns:
List of matching path strings.
- Return type:
T.List[str]
- async aiomegfile.smart.smart_iglob(path: str | PathLike, *, recursive: bool = True) AsyncIterator[str][source]
Yield paths whose paths match the glob pattern.
- Parameters:
path – Base path to search under.
recursive – If False,
**will not search directory recursively.
- Returns:
Async iterator of matching path strings.
- Return type:
T.AsyncIterator[str]
- async aiomegfile.smart.smart_isabs(path: str | PathLike) bool[source]
Test whether a path is absolute.
- Parameters:
path – Given path.
- Returns:
True if a path is absolute, else False.
- Return type:
bool
- async aiomegfile.smart.smart_isdir(path: str | PathLike, *, followlinks: bool = False) bool[source]
Return True if the path points to a directory.
- Parameters:
path – Path to check.
followlinks – Whether to follow symbolic links.
- Returns:
True if the path is a directory, otherwise False.
- async aiomegfile.smart.smart_isfile(path: str | PathLike, *, followlinks: bool = False) bool[source]
Return True if the path points to a regular file.
- Parameters:
path – Path to check.
followlinks – Whether to follow symbolic links.
- Returns:
True if the path is a regular file, otherwise False.
- async aiomegfile.smart.smart_islink(path: str | PathLike) bool[source]
Return True if the path points to a symbolic link.
- Parameters:
path – Path to check.
- Returns:
True if the path is a symlink, otherwise False.
- async aiomegfile.smart.smart_listdir(path: str | PathLike) List[str][source]
Return names of entries in the given directory.
- Parameters:
path – Directory path to list.
- Returns:
List of entry names.
- Return type:
T.List[str]
- async aiomegfile.smart.smart_load_content(path: str | PathLike, start: int | None = None, stop: int | None = None) bytes[source]
Get specified file range in bytes.
- Parameters:
path – Specified path.
start – Start index.
stop – Stop index (exclusive).
- Returns:
Bytes content in range
[start, stop).- Return type:
bytes
- Raises:
ValueError – If stop is less than start.
- async aiomegfile.smart.smart_load_from(path: str | PathLike) BinaryIO[source]
Read content in binary from the specified path into memory.
Caller is responsible for closing the returned BinaryIO.
- Parameters:
path – Specified path to read.
- Returns:
BinaryIO containing file content.
- Return type:
T.BinaryIO
- async aiomegfile.smart.smart_load_text(path: str | PathLike) str[source]
Read text content from the specified path.
- Parameters:
path – Path to read.
- Returns:
File content as text.
- Return type:
str
- async aiomegfile.smart.smart_makedirs(path: str | PathLike, *, mode: int = 511, exist_ok: bool = False) None[source]
Create a directory and any missing parents.
- Parameters:
path – Directory path to create.
mode – Permission bits for the new directory.
exist_ok – Whether to ignore if the directory exists.
- Raises:
FileExistsError – When directory exists and exist_ok is False.
- async aiomegfile.smart.smart_move(src_path: str | PathLike, dst_path: str | PathLike) str[source]
Move a file or directory and return the destination path string.
- Parameters:
src_path – Source path to move.
dst_path – Destination path.
- Returns:
Destination path string.
- Return type:
str
- aiomegfile.smart.smart_open(path: str | PathLike, mode: str = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None) AsyncContextManager[source]
Open the file with mode.
- Parameters:
path – File path to open.
mode – File open mode.
buffering – Buffering policy.
encoding – Text encoding in text mode.
errors – Error handling strategy.
newline – Newline handling policy in text mode.
- Returns:
Async file context manager.
- Return type:
T.AsyncContextManager
- async aiomegfile.smart.smart_path_join(path: str | PathLike, *paths: str | PathLike) str[source]
Join path components and return the combined path string.
- Parameters:
path – Base path.
paths – Additional path components to join.
- Returns:
Combined path string.
- Return type:
str
- async aiomegfile.smart.smart_readlink(path: str | PathLike) str[source]
Return the target path string of a symbolic link.
- Parameters:
path – Path to the symbolic link.
- Returns:
Target path string.
- Return type:
str
- async aiomegfile.smart.smart_realpath(path: str | PathLike, *, strict: bool = False) str[source]
Resolve symlinks and return the absolute path string.
- Parameters:
path – Path to resolve.
strict – Whether to raise if a symlink points to itself.
- Returns:
Resolved absolute path string.
- Return type:
str
- Raises:
OSError – If a symlink points to itself and strict is True.
- async aiomegfile.smart.smart_relpath(path: str | PathLike, start: str | PathLike) str[source]
Compute a relative path from start to path.
- Parameters:
path – Target path.
start – Base path to compute the relative path against.
- Returns:
Relative path string.
- Return type:
str
- Raises:
ValueError – If path is not under the given start path.
- async aiomegfile.smart.smart_remove(path: str | PathLike, missing_ok: bool = False) None[source]
Remove (delete) the file or directory.
- Parameters:
path – Path to remove.
missing_ok – If False, raise when the path does not exist.
- Raises:
FileNotFoundError – When missing_ok is False and the path is absent.
- async aiomegfile.smart.smart_rename(src_path: str | PathLike, dst_path: str | PathLike) str[source]
Rename a file or directory and return the destination path string.
- Parameters:
src_path – Source path to rename.
dst_path – Destination path.
- Returns:
Destination path string.
- Return type:
str
- async aiomegfile.smart.smart_save_as(file_object: BinaryIO, path: str | PathLike) None[source]
Write an opened binary stream to the specified path.
The input stream will not be closed.
- Parameters:
file_object – Stream to be read.
path – Target path to save the stream content.
- async aiomegfile.smart.smart_save_content(path: str | PathLike, content: bytes) None[source]
Save bytes content to the specified path.
- Parameters:
path – Path to save content.
content – Bytes content to write.
- async aiomegfile.smart.smart_save_text(path: str | PathLike, text: str) None[source]
Save text to the specified path.
- Parameters:
path – Path to save text.
text – Text content to write.
- async aiomegfile.smart.smart_scan(path: str | PathLike, *, missing_ok: bool = True, followlinks: bool = False) AsyncIterator[str][source]
Iteratively traverse only files in the given path.
If the path is a file, yields that file only.
- Parameters:
path – Given path.
missing_ok – If False and the path is missing, raise FileNotFoundError.
followlinks – Whether to follow symbolic links.
- Returns:
Async iterator of file paths.
- Return type:
T.AsyncIterator[str]
- aiomegfile.smart.smart_scandir(path: str | PathLike) AsyncContextManager[AsyncIterator[FileEntry]][source]
Return an async context manager for iterating directory entries.
- Parameters:
path – Directory path to scan.
- Returns:
Async context manager producing FileEntry items.
- Return type:
T.AsyncContextManager[T.AsyncIterator[FileEntry]]
- async aiomegfile.smart.smart_stat(path: str | PathLike, *, follow_symlinks: bool = False) StatResult[source]
Get the status of the path.
- Parameters:
path – Path to stat.
follow_symlinks – Whether to follow symbolic links when resolving.
- Returns:
StatResult for the path.
- Return type:
StatResult
- async aiomegfile.smart.smart_symlink(src_path: str | PathLike, dst_path: str | PathLike) None[source]
Create a symbolic link at dst_path pointing to src_path.
- Parameters:
src_path – Target path the link should point to.
dst_path – Path of the symlink to create.
- Raises:
TypeError – If src_path and dst_path are on different filesystems.
- async aiomegfile.smart.smart_sync(src_path: str | PathLike, dst_path: str | PathLike, callback: Callable[[int], None] | None = None, callback_after_copy_file: Callable[[str, str], None] | None = None, followlinks: bool = False, force: bool = False, overwrite: bool = True) None[source]
Sync file or directory to the destination path.
Note
When the parameter is file, this function behaves like
smart_copy.If file and directory of same name and same level, sync considers it as file first.
- Parameters:
src_path – Given source path.
dst_path – Given destination path.
callback – Called periodically during copy with bytes written.
callback_after_copy_file – Called after copy success, and the input parameter is src file path and dst file path.
followlinks – False if regard symlink as file, else True.
force – Sync file forcible, do not ignore same files, priority is higher than
overwrite.overwrite – Whether to overwrite files when they already exist.
- Raises:
FileNotFoundError – If source path does not exist.
- async aiomegfile.smart.smart_touch(path: str | PathLike, exist_ok: bool = True) None[source]
Create the file if missing, optionally raising on existence.
- Parameters:
path – Path to create.
exist_ok – Whether to skip raising if the file already exists.
- async aiomegfile.smart.smart_unlink(path: str | PathLike, missing_ok: bool = False) None[source]
Remove (delete) the file.
- Parameters:
path – Path to remove.
missing_ok – If False, raise when the path does not exist.
- Raises:
FileNotFoundError – When missing_ok is False and the file is absent.
IsADirectoryError – If the target is a directory.
- async aiomegfile.smart.smart_walk(path: str | PathLike, *, followlinks: bool = False) AsyncIterator[Tuple[str, List[str], List[str]]][source]
Generate the file names in a directory tree by walking the tree.
- Parameters:
path – Root directory to walk.
followlinks – Whether to traverse symbolic links to directories.
- Returns:
Async iterator of (root, dirs, files).
- Return type:
T.AsyncIterator[T.Tuple[str, T.List[str], T.List[str]]]