Abstract interface#
The abstract base classes that define the unified storage contract. Both the AWS S3 and GCS implementations derive from these, so you can write code against the abstract types to stay provider-agnostic.
unicloud.abstract_class.CloudStorageFactory
#
Bases: ABC
Provider-level cloud-storage client contract.
Every concrete provider (AWS S3, Google Cloud Storage, ...) must subclass this ABC and implement
:meth:create_client, :meth:client, :meth:upload, :meth:download, and :meth:get_bucket.
Callers that want to stay provider-agnostic should accept CloudStorageFactory and only call
the methods declared here.
Examples:
- Accept either provider in a type-annotated function:
Source code in src/unicloud/abstract_class.py
client
abstractmethod
property
#
Return the cached provider SDK client.
Returns:
| Type | Description |
|---|---|
|
The same instance that :meth: |
create_client()
abstractmethod
#
Construct and return the underlying provider SDK client.
Implementations read credentials from environment variables (or accept a provider-specific
config argument) and return the native client object — for example a boto3.client for AWS
or a google.cloud.storage.Client for GCS.
Returns:
| Type | Description |
|---|---|
|
The provider-specific SDK client instance. Type varies by provider. |
Source code in src/unicloud/abstract_class.py
upload(file_path, destination)
abstractmethod
#
Upload a single local file to the provider.
This is a convenience helper on the factory; prefer :meth:get_bucket + the bucket-level
upload for anything non-trivial (overwrite handling, directory uploads, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path to the local file to upload. |
required | |
destination
|
Destination in the provider. The convention used by both shipped providers
is |
required |
Source code in src/unicloud/abstract_class.py
download(source, file_path)
abstractmethod
#
Download a single object to a local path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Provider-side path. Both shipped providers use |
required | |
file_path
|
Local destination path for the downloaded file. |
required |
Source code in src/unicloud/abstract_class.py
get_bucket(bucket_name)
abstractmethod
#
Return a bucket handle for per-object operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_name
|
The name (or ID) of the bucket to look up. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AbstractBucket |
AbstractBucket
|
A concrete :class: |
Source code in src/unicloud/abstract_class.py
unicloud.abstract_class.AbstractBucket
#
Bases: ABC
Per-bucket operation contract.
A bucket handle exposes upload/download/delete/list/exists for a single bucket. Both providers
ship a :class:Bucket class that subclasses this ABC and shares the same method names; provider
parity is intentional.
Examples:
- Type-annotate a helper that works with either provider's bucket:
Source code in src/unicloud/abstract_class.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
name
abstractmethod
property
#
Return the bucket name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
The bucket's name (AWS) or ID (GCS). |
__str__()
abstractmethod
#
Return a short, human-readable representation of the bucket.
Returns:
| Name | Type | Description |
|---|---|---|
str |
Usually |
__repr__()
abstractmethod
#
Return a developer-facing representation of the bucket.
Returns:
| Name | Type | Description |
|---|---|---|
str |
Usually the same as :meth: |
upload(local_path, bucket_path, overwrite=False)
abstractmethod
#
Upload a file or directory into the bucket.
Implementations must accept both single files and directories; when local_path is a
directory, the upload is recursive and preserves the relative tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
Union[str, Path]
|
Local file or directory to upload. |
required |
bucket_path
|
Union[str, Path]
|
Destination prefix inside the bucket. |
required |
overwrite
|
bool
|
If |
False
|
Source code in src/unicloud/abstract_class.py
download(bucket_path, local_path, overwrite=False)
abstractmethod
#
Download a file or directory out of the bucket.
A trailing / on bucket_path signals a directory download; otherwise a single object
is fetched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_path
|
str
|
Source path inside the bucket. Trailing |
required |
local_path
|
Union[str, Path]
|
Local destination path. |
required |
overwrite
|
bool
|
If |
False
|
Source code in src/unicloud/abstract_class.py
delete(bucket_path)
abstractmethod
#
Delete a file or directory from the bucket.
A trailing / on bucket_path signals a recursive directory delete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_path
|
str
|
Path inside the bucket to delete. |
required |
Source code in src/unicloud/abstract_class.py
list_files()
abstractmethod
#
List the objects in the bucket.
Implementations may accept provider-specific filtering arguments (prefix, glob pattern, max results, ...) as additional parameters.
Returns:
| Type | Description |
|---|---|
|
list[str]: Object keys, in provider-defined order. |
Source code in src/unicloud/abstract_class.py
file_exists(file_name)
abstractmethod
#
Return whether an object exists in the bucket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
Object key to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|