tlcurl.url_adapter
¶
Provides a unified interface for URL-based file operations across different schemes and storage backends.
Module Contents¶
Classes¶
Class |
Description |
---|---|
An Enum indicating what to do if content already exists at the target URL |
|
The base class for all directory entries. |
|
The base class for all URL adapters |
|
A UrlAdapter where the Async methods are implemented as Futures that call the equivalent Sync methods on the thread pool |
|
A UrlAdapter where the Sync methods are implemented by calling the equivalent Async methods and then waiting on the Futures returned. |
Data¶
Data |
Description |
---|---|
API¶
- logger = getLogger(...)¶
- class IfExistsOption¶
-
An Enum indicating what to do if content already exists at the target URL
from tlc.core.url_adapter import IfExistsOption, UrlAdapter from tlc.core.url import Url url = Url("s3://my-bucket/my-file.txt") adapter = UrlAdapter.get_adapter(url) adapter.write_string_content_to_url(url, "Hello World!", IfExistsOption.OVERWRITE)
Initialize self. See help(type(self)) for accurate signature.
- OVERWRITE = overwrite¶
If content already exists at the target URL, overwrite the content (default).
- RENAME = rename¶
If content already exists at the target URL, leave that content, and write the new content to a new URL that is similar to the original target URL.
- RAISE = raise¶
If content already exists at the target URL, raise an exception.
- REUSE = reuse¶
If content already exists at the target URL, reuse the existing content.
- class UrlAdapterDirEntry¶
The base class for all directory entries.
- class UrlAdapter¶
Bases:
abc.ABC
The base class for all URL adapters
- abstract read_string_content_from_url(
- url: Url,
Read content from URL synchronously, dispatch
- abstract read_string_content_from_url_async(
- url: Url,
Read content from URL asynchronously
- abstract read_binary_content_from_url(
- url: Url,
Read binary content from URL synchronously, dispatch
- abstract read_binary_content_from_url_async(
- url: Url,
Read binary content from URL asynchronously
- write_string_content_to_url(
- url: Url,
- content: str,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Write content to URL synchronously
- abstract write_string_content_to_url_async(
- url: Url,
- content: str,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Write content to URL asynchronously
- write_binary_content_to_url(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Write binary content to URL synchronously
Handles write options and dispatches to
_write_binary_content_to_url
- abstract write_binary_content_to_url_async(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Write binary content to URL asynchronously
- copy_url(
- source: Url,
- destination: Url,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Copy URL synchronously
- abstract copy_url_async(
- source: Url,
- destination: Url,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Copy URL asynchronously
- abstract make_dirs( ) None ¶
Create a leaf directory and all intermediate ones synchronously
For flat file hierarchies, this may be a no-op, see
is_file_hierarchy_flat
.
- abstract make_dirs_async( ) Future ¶
Create a leaf directory and all intermediate ones asynchronously
For flat file hierarchies, this may be a no-op, see
is_file_hierarchy_flat
.
- abstract get_file_size_async(
- url: Url,
Get the size of the file at the given URL asynchronously
- abstract list_dir(
- url: Url,
List the entries belonging to the directory at the given URL synchronously
- abstract list_dir_async(
- url: Url,
List the entries belonging to the directory at the given URL asynchronously
- abstract exists(
- url: Url,
Return True if the given URL refers to an existing path synchronously
- abstract exists_async(
- url: Url,
Return True if the given URL refers to an existing path asynchronously
- abstract is_dir(
- url: Url,
Return True if the given URL refers to a directory synchronously
- abstract is_dir_async(
- url: Url,
Return True if the given URL refers to a directory asynchronously
- abstract is_writable_async(
- url: Url,
Return True if the given URL is writable asynchronously
- is_file_hierarchy_flat() bool ¶
Determine if the file hierarchy is flat for this adapter
Cloud storage normally has a flat hierarchy, meaning that
make_dirs
is a no-op.
- abstract stat(
- url: Url,
- Get metadata about a file or directory at the given URL synchronously
param url: The URL to get metadata for
return: A UrlAdapterDirEntry containing metadata about the file or directory
raises FileNotFoundError: If the URL does not exist
- class UrlAdapterAsyncFromSync¶
Bases:
tlcurl.url_adapter.UrlAdapter
A UrlAdapter where the Async methods are implemented as Futures that call the equivalent Sync methods on the thread pool
Derived classes must implement the Sync methods.
- write_string_content_to_url_async(
- url: Url,
- content: str,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- write_binary_content_to_url_async(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- copy_url_async(
- source: Url,
- destination: Url,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- class UrlAdapterSyncFromAsync¶
Bases:
tlcurl.url_adapter.UrlAdapter
A UrlAdapter where the Sync methods are implemented by calling the equivalent Async methods and then waiting on the Futures returned.
Derived classes must implement the Async methods.
- write_string_content_to_url(
- url: Url,
- content: str,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- write_binary_content_to_url(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- list_dir(
- url: Url,
- stat(
- url: Url,