aiomegfile.filesystem.local module

class aiomegfile.filesystem.local.LocalFileSystem(protocol_in_path: bool)[source]

Bases: BaseFileSystem

Protocol for local filesystem operations.

async absolute(path: str) str[source]

Make the path absolute, without normalization or resolving symlinks. Returns a new path object.

Parameters:

path – Path to convert.

Returns:

Absolute version of the provided path.

build_uri(path: str) str[source]

Build URI for the filesystem by path part.

Parameters:

path – Path without protocol.

Returns:

URI string.

async copy(src_path: str, dst_path: str, callback: Callable[[int], None] | None = None) str[source]

copy single file, not directory

Parameters:
  • src_path – Given source path

  • dst_path – Given destination path

  • callback – Called periodically during copy with bytes written.

Returns:

Destination path after copy.

async exists(path: str, 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.

classmethod from_uri(uri: str) LocalFileSystem[source]

Create LocalFileSystem from uri string.

Parameters:

uri – URI string.

Returns:

LocalFileSystem instance.

async is_dir(path: str, 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 is_file(path: str, 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.

Return True if the path points to a symbolic link.

Parameters:

path – Path to check.

Returns:

True if the path is a symbolic link, otherwise False.

async mkdir(path: str, mode: int = 511, parents: bool = False, exist_ok: bool = False) None[source]

Create a directory.

Parameters:
  • path – Directory path to create.

  • mode – Permission bits for the new directory.

  • parents – Whether to create missing parents.

  • exist_ok – Whether to ignore if the directory exists.

Raises:

FileExistsError – When directory exists and exist_ok is False.

async move(src_path: str, dst_path: str, overwrite: bool = True) str[source]

Move file or directory.

Parameters:
  • src_path – Source path to move.

  • dst_path – Given destination path

  • overwrite – whether or not overwrite file when exists

Raises:

FileExistsError – If overwrite is False and destination exists.

Returns:

The destination path

open(path: str, 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 when using text modes.

  • errors – Error handling strategy for encoding/decoding.

  • newline – Newline handling in text mode.

Returns:

Async file context manager.

parse_uri(uri: str) str[source]

Parse the path part from a URI.

Parameters:

uri – URI string.

Returns:

Path part string.

protocol = 'file'

Return a new path representing the symbolic link’s target.

Parameters:

path – Path to the symbolic link.

Returns:

Target path of the symbolic link.

async remove(path: str, missing_ok: bool = False) None[source]

Remove (delete) the file or directory.

If path is a file, remove it directly. If path is a directory, remove it and all its contents recursively.

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.

same_endpoint(other_filesystem: BaseFileSystem) bool[source]

Local filesystem endpoints match when protocols match.

Parameters:

other_filesystem – Filesystem to compare.

Returns:

True if both represent the same endpoint.

async samefile(path: str, other_path: str) bool[source]

Return True if the path points to the same file as other_path.

Parameters:
  • path – First path to compare.

  • other_path – Other path to compare.

Returns:

True if both paths point to the same file, otherwise False.

scandir(path) AsyncContextManager[AsyncIterator[FileEntry]][source]

Return an async context manager for iterating directory entries.

Parameters:

path – Directory to scan.

Returns:

Async context manager producing FileEntry items.

scanfile(path) AsyncContextManager[AsyncIterator[FileEntry]][source]

Iteratively traverse only files in given directory. Every iteration on generator yields FileEntry object.

Returns:

Async context manager yielding an async iterator of FileEntry objects.

Return type:

T.AsyncContextManager[T.AsyncIterator[FileEntry]]

async stat(path: str, followlinks: bool = False) StatResult[source]

Get the status of the path.

Parameters:
  • path – Path to stat.

  • followlinks – Whether to follow symbolic links.

Raises:

FileNotFoundError – If the path does not exist.

Returns:

Populated StatResult for the path.

Create a symbolic link pointing to src_path named dst_path.

Parameters:
  • src_path – Source path the link should reference.

  • dst_path – The symbolic link path.