aiomegfile.filesystem.http module
- class aiomegfile.filesystem.http.AioHttpAdaptiveReader(uri: str, mode: str, timeout: float, max_retries: int, encoding: str, errors: str, newline: str | None, block_size: int, max_buffer_size: int, block_forward: int | None)[source]
Bases:
AioReadable,AioSeekableAdaptive HTTP reader selecting prefetch or full-content strategy.
- async close() None
Close selected reader if initialized.
- property mode: str
Return open mode.
- Returns:
File mode string.
- Return type:
str
- property name: str
Return source URI.
- Returns:
URI string.
- Return type:
str
- async read(size: int | None = None) AnyStr[source]
Read content from current position.
- Parameters:
size – Maximum size to read.
- Returns:
Read bytes or text.
- Return type:
T.AnyStr
- async readline(size: int | None = None) AnyStr[source]
Read one line from current position.
- Parameters:
size – Maximum size to read.
- Returns:
One line in bytes or text.
- Return type:
T.AnyStr
- class aiomegfile.filesystem.http.AioHttpContentReader(uri: str, mode: str, timeout: float, max_retries: int, encoding: str, errors: str, newline: str | None)[source]
Bases:
AioReadableAsync reader for streaming HTTP response content.
- async close() None
Close reader and release HTTP resources.
- property mode: str
Return open mode.
- Returns:
File mode string.
- Return type:
str
- property name: str
Return source URI.
- Returns:
URI string.
- Return type:
str
- async read(size: int | None = None) AnyStr[source]
Read content from current position.
- Parameters:
size – Maximum size to read.
- Returns:
Read bytes or text.
- Return type:
T.AnyStr
- class aiomegfile.filesystem.http.HttpFileSystem(timeout: float = 60.0)[source]
Bases:
BaseFileSystemFilesystem adapter for read-only HTTP resources.
- build_uri(path: str) str
Build URI from path.
- Parameters:
path – Path without protocol.
- Returns:
URI string.
- Return type:
str
- async exists(path: str, followlinks: bool = False) bool[source]
Return whether path points to an existing HTTP resource.
- Parameters:
path – Target path without protocol.
followlinks – Ignored for HTTP protocol.
- Returns:
True when resource exists, otherwise False.
- Return type:
bool
- classmethod from_uri(uri: str)
Create a new filesystem instance from URI.
- Parameters:
uri – URI string.
- Returns:
HttpFileSystem instance.
- Return type:
- async is_dir(path: str, followlinks: bool = False) bool[source]
Return whether path points to a directory.
HTTP resources are treated as files only.
- Parameters:
path – Target path without protocol.
followlinks – Ignored for HTTP protocol.
- Returns:
Always False.
- Return type:
bool
- async is_file(path: str, followlinks: bool = False) bool[source]
Return whether path points to an existing HTTP resource.
- Parameters:
path – Target path without protocol.
followlinks – Ignored for HTTP protocol.
- Returns:
True when resource exists, otherwise False.
- Return type:
bool
- open(path: str, mode: str = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None, **kwargs: Any) AsyncContextManager[source]
Open a read-only HTTP resource.
- Parameters:
path – Target path without protocol.
mode – Open mode, supports
r/rt/rb.buffering – Ignored, kept for API compatibility.
encoding – Text encoding in text mode.
errors – Text decoding error handling strategy.
newline – Newline handling in text mode.
kwargs –
Extra options for compatibility with megfile APIs.
Supported options:
block_size: Prefetch block size in bytes.max_buffer_size: Maximum in-memory prefetch buffer size in bytes.block_forward: Number of blocks to prefetch ahead.max_retries: Maximum retry attempts for transient HTTP errors.
- Returns:
Async reader context manager.
- Return type:
T.AsyncContextManager
- parse_uri(uri: str) str[source]
Parse path part from URI.
- Parameters:
uri – URI string.
- Returns:
Path without protocol.
- Return type:
str
- protocol = 'http'
- same_endpoint(other_filesystem: BaseFileSystem) bool[source]
Return whether this filesystem points to the same endpoint.
- Parameters:
other_filesystem – Filesystem to compare.
- Returns:
True when both are HTTP filesystems with same protocol.
- Return type:
bool
- scandir(path: str) AsyncContextManager[AsyncIterator[Any]][source]
Scan entries under a path.
HTTP protocol does not support directory listing.
- Parameters:
path – Target path without protocol.
- Raises:
NotADirectoryError – Always raised for HTTP resources.
- scanfile(path: str, sort: bool = False) AsyncContextManager[AsyncIterator[Any]][source]
Scan files under a path.
HTTP protocol does not support directory traversal.
- Parameters:
path – Target path without protocol.
sort – Compatibility flag for protocol-aligned scanfile APIs.
- Raises:
NotADirectoryError – Always raised for HTTP resources.
- async stat(path: str, followlinks: bool = False) StatResult[source]
Get metadata for an HTTP resource.
- Parameters:
path – Target path without protocol.
followlinks – Ignored for HTTP protocol.
- Returns:
StatResult for the HTTP resource.
- Return type:
- Raises:
FileNotFoundError – When resource does not exist.
PermissionError – When request is denied.
OSError – When request fails for other reasons.
- class aiomegfile.filesystem.http.HttpsFileSystem(timeout: float = 60.0)[source]
Bases:
HttpFileSystemFilesystem adapter for HTTPS resources.
- protocol = 'https'