Platforms¶
base
¶
Abstract base class for platform (file system and secrets) operations.
Every concrete platform — Local, Fabric, Databricks, AWS — inherits from
:class:BasePlatform and implements all abstract methods.
BasePlatform
¶
Bases: BaseSecretProvider
Abstract interface for file/directory operations and secret retrieval.
Platforms encapsulate the storage layer differences (local FS, ADLS,
S3, DBFS) behind a uniform API so that the rest of the framework
never touches os, shutil, or cloud SDKs directly.
Each platform also implements :meth:_fetch_secret so it can serve as
its own :class:~datacoolie.core.secrets.provider.BaseSecretProvider,
using its existing SDK handle (env vars / notebookutils / dbutils / boto3).
18 abstract requirements across six categories: 17 methods declared
here plus the inherited _fetch_secret requirement:
- File I/O — read / write / append / delete text content
- Directory Ops — create / delete / list files / list folders
- Existence Checks — file_exists / folder_exists
- File Management — upload / download / copy / move / get_file_info
- Binary I/O — read_bytes / write_bytes
- Secrets —
_fetch_secret(inherited from BaseSecretProvider)
append_file
abstractmethod
¶
Append text content to an existing file.
If the file does not exist, create it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path or URI for the target file. |
required |
content
|
str
|
Text to append. |
required |
Raises:
| Type | Description |
|---|---|
PlatformError
|
On I/O failure. |
copy_file
abstractmethod
¶
Copy a file from src to dest.
A normalized source/destination pair that identifies the same file is an idempotent no-op and must not issue a destructive self-copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source file path. |
required |
dest
|
str
|
Destination file path. |
required |
overwrite
|
bool
|
Allow overwriting an existing file at dest. |
False
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If source does not exist or dest exists without overwrite. |
create_folder
abstractmethod
¶
Create a directory (including any missing parents).
No-op if the directory already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path or URI. |
required |
Raises:
| Type | Description |
|---|---|
PlatformError
|
On failure. |
delete_file
abstractmethod
¶
Delete a file.
No-op if the file does not exist (idempotent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path or URI to delete. |
required |
Raises:
| Type | Description |
|---|---|
PlatformError
|
On I/O failure. |
delete_folder
abstractmethod
¶
Delete a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path or URI. |
required |
recursive
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If recursive is |
download_file
abstractmethod
¶
Download a file from this platform to the local filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source path on this platform. |
required |
dest
|
str
|
Absolute path on the local OS filesystem to write to. |
required |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the source does not exist or the download fails. |
file_exists
abstractmethod
¶
Return True if the path refers to an existing file.
folder_exists
abstractmethod
¶
Return True if the path refers to an existing directory.
get_file_info
abstractmethod
¶
get_file_info(path: str) -> FileInfo
Return metadata about a single file or directory.
Returns:
| Name | Type | Description |
|---|---|---|
A |
FileInfo
|
class: |
FileInfo
|
|
|
FileInfo
|
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the path does not exist. |
list_files
abstractmethod
¶
list_files(
path: str,
*,
recursive: bool = False,
extension: str | None = None,
) -> list[FileInfo]
List files under path.
Each entry is a :class:FileInfo instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path or URI. |
required |
recursive
|
bool
|
Descend into sub-directories. |
False
|
extension
|
str | None
|
Filter by suffix (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
list[FileInfo]
|
List of :class: |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the path does not exist or is not a directory. |
list_folders
abstractmethod
¶
List immediate (or recursive) sub-directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path or URI. |
required |
recursive
|
bool
|
Descend into sub-directories. |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of directory paths. |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If path is not a directory. |
move_file
abstractmethod
¶
Move (rename) a file from src to dest.
A normalized source/destination pair that identifies the same file is an idempotent no-op.
Implementations create missing destination parent directories. A
failed move retains the source. When overwrite is False, an
existing destination is preserved and causes an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source file path. |
required |
dest
|
str
|
Destination file path. |
required |
overwrite
|
bool
|
Allow overwriting an existing file at dest. |
False
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If source does not exist or dest exists without overwrite. |
read_bytes
abstractmethod
¶
Return the entire file contents as bytes.
Implementations MUST NOT use bounded head()-style APIs that
truncate large files. Prefer the platform's fastest native unbounded
primitive (e.g. s3.get_object for AWS, direct open(path, "rb")
for Unity Catalog Volumes, fs.cp to a temp file for other
cloud paths).
Suitable for files that fit comfortably in memory.
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the file does not exist or cannot be read. |
read_bytes_under_base
¶
Read binary content below a configured base with the same guard.
read_file
abstractmethod
¶
Read the entire content of a text file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path or URI to the file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
File content as a string. |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the file does not exist or cannot be read. |
read_file_under_base
¶
Read a relative resource below a configured base path.
Query/artifact resolution uses this narrow helper so the selected
base is validated before the platform performs I/O. Concrete
platforms may override it when their storage backend has additional
canonical-path rules (LocalPlatform rejects symlink escapes).
relative_path_under_base
¶
Return a listed path relative to a configured base.
Platform listings may return either the same logical spelling as the requested root or a canonical/absolute spelling. The default handles the former; local adapters override it to validate the latter against their canonical sandbox before returning a relative resource path.
upload_file
abstractmethod
¶
Upload a file from the local filesystem to the platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
str
|
Absolute path on the local OS filesystem. |
required |
dest
|
str
|
Destination path on this platform. |
required |
overwrite
|
bool
|
Allow overwriting an existing file at dest. |
False
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If local_path does not exist or dest exists without overwrite. |
write_bytes
abstractmethod
¶
Write raw bytes to path.
Symmetric counterpart of :meth:read_bytes. Prefer the platform's
fastest native upload primitive. For very large payloads, write to a
temp file and call :meth:upload_file directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination path or URI. |
required |
data
|
bytes
|
Bytes to write. |
required |
overwrite
|
bool
|
Allow overwriting an existing file at path. |
False
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the file exists and overwrite is |
write_file
abstractmethod
¶
Write text content to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path or URI for the target file. |
required |
content
|
str
|
Text to write. |
required |
overwrite
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
PlatformError
|
If the file exists and overwrite is |
FileInfo
dataclass
¶
FileInfo(
name: str,
path: str,
modification_time: Optional[datetime],
size: int = 0,
is_dir: bool = False,
)
Metadata for a single file-system entry.
Returned by :meth:BasePlatform.list_files and
:meth:BasePlatform.get_file_info. frozen=True makes instances
immutable and hashable; slots=True reduces per-instance memory.
local_platform
¶
Local filesystem platform implementation.
Uses pathlib, os, and shutil for all operations.
Suitable for local development, testing, and single-node environments.
LocalPlatform
¶
Bases: BasePlatform
Platform backed by the local filesystem.
Also implements :meth:_fetch_secret via os.environ, so it can
serve as its own secret provider in local / test environments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str | None
|
Optional root directory. When set, all relative paths are resolved against this root. |
None
|
cache_ttl
|
int
|
Secret cache time-to-live in seconds (default 300).
Pass |
300
|
read_bytes_under_base
¶
Read binary content while enforcing the selected root canonically.
read_file_under_base
¶
Read a resource while enforcing the selected base's real path.
LocalPlatform may itself be sandboxed, but the Driver can select a
narrower artifact/SQL root within that sandbox. Check both roots so a
symlink or junction cannot redirect a query file outside the selected
component directory.
relative_path_under_base
¶
Relativize a listing entry after canonical sandbox validation.
write_bytes
¶
Zero-overhead native write — no temp file.
aws_platform
¶
AWS-first platform facade backed by boto3 and S3-compatible storage.
The implementation is split into private components under platforms._aws.
The public class remains stable for AWS S3, while endpoint_url allows the
same S3 filesystem contract to be used with MinIO and LocalStack.
AWSPlatform
¶
AWSPlatform(
bucket: str = "",
region: str | None = None,
profile: str | None = None,
endpoint_url: str | None = None,
cache_ttl: int = 300,
)
Bases: BasePlatform
Platform backed by AWS S3 via boto3.
The storage portion also works with S3-compatible endpoints such as MinIO
when endpoint_url is supplied. Secrets Manager, Glue, and Athena remain
AWS service integrations and use their normal AWS endpoints by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket
|
str
|
Default S3 bucket name. |
''
|
region
|
str | None
|
AWS region for S3 and AWS service operations. |
None
|
profile
|
str | None
|
Named AWS profile from |
None
|
endpoint_url
|
str | None
|
Custom S3 endpoint for MinIO, LocalStack, or similar. |
None
|
cache_ttl
|
int
|
Secret cache time-to-live in seconds (default 300). Pass |
300
|
boto3_client
¶
Create a boto3 service client using the platform's credentials.
The platform endpoint_url is a storage override and is injected
automatically only for S3. Callers may pass an explicit endpoint for any
service through kwargs.
fabric_platform
¶
Portable Microsoft Fabric platform facade.
NotebookUtils remains the preferred backend inside Fabric. External Python
runtimes use the Azure Data Lake and Key Vault SDKs with Microsoft Entra
credentials while callers keep the same :class:FabricPlatform API.
FabricPlatform
¶
FabricPlatform(
cache_ttl: int = 300,
*,
runtime: FabricRuntime = "auto",
azure_credential: TokenCredential | None = None,
)
Bases: BasePlatform
Access OneLake or ADLS through the best backend for the current runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_ttl
|
int
|
Secret cache time-to-live in seconds. Pass |
300
|
runtime
|
FabricRuntime
|
|
'auto'
|
azure_credential
|
TokenCredential | None
|
Optional Azure |
None
|
notebookutils
property
¶
Return native NotebookUtils; unavailable in explicit external mode.
close
¶
Release owned Azure resources once, after consumers have quiesced.
Close is terminal. Concurrent service I/O and close are unsupported. Injected credentials and native NotebookUtils handles remain borrowed.
get_secret
¶
Fetch a secret while open, including reads from the inherited cache.
databricks_platform
¶
Portable Databricks platform facade.
Native Databricks runtimes prefer dbutils and direct POSIX content I/O for
Unity Catalog Volumes. Other Python runtimes use WorkspaceClient.files
with Databricks unified authentication.
DatabricksPlatform
¶
DatabricksPlatform(
dbutils: Any | None = None,
cache_ttl: int = 300,
*,
runtime: DatabricksRuntime = "auto",
workspace_client: Any | None = None,
)
Bases: BasePlatform
Access Databricks storage through the best backend for the runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dbutils
|
Any | None
|
Optional native Databricks utilities handle. |
None
|
cache_ttl
|
int
|
Secret cache time-to-live in seconds. Pass |
300
|
runtime
|
DatabricksRuntime
|
|
'auto'
|
workspace_client
|
Any | None
|
Optional injected |
None
|
Fabric lifecycle¶
FabricPlatform.close() releases its owned Azure root clients and internally
created credential once. Quiesce callers before close; overlapping service I/O
and close is unsupported. Close is terminal, including cached secret reads and
file operations. Injected credentials and native NotebookUtils handles remain
borrowed. Driver does not close a supplied platform.
Secret provider extension hook¶
BasePlatform inherits the secret-provider contract. Platform implementations override the
focused provider hook below to fetch one secret from their native vault; the public get_secret
method retains caching and delegates to it.
_fetch_secret
abstractmethod
¶
Retrieve a secret from the underlying vault.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Vault key / secret name. Its meaning is platform-specific: secret key name for Databricks/Fabric/Local, or JSON field name within the secret for AWS. |
required |
source
|
str
|
Source identifier whose meaning is platform-specific:
scope for Databricks, vault URL for Fabric, env prefix for
Local, and secret name/ARN ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
The secret value as a string. |
Raises:
| Type | Description |
|---|---|
DataCoolieError
|
On failure. |