panpath 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
panpath/clients.py ADDED
@@ -0,0 +1,273 @@
1
+ """Base client classes for sync and async cloud storage operations."""
2
+ from abc import ABC, abstractmethod
3
+ from typing import Any, BinaryIO, Iterator, Optional, TextIO, Union
4
+
5
+
6
+ class Client(ABC):
7
+ """Base class for synchronous cloud storage clients."""
8
+
9
+ @abstractmethod
10
+ def exists(self, path: str) -> bool:
11
+ """Check if path exists."""
12
+ ...
13
+
14
+ @abstractmethod
15
+ def read_bytes(self, path: str) -> bytes:
16
+ """Read file as bytes."""
17
+ ...
18
+
19
+ @abstractmethod
20
+ def read_text(self, path: str, encoding: str = "utf-8") -> str:
21
+ """Read file as text."""
22
+ ...
23
+
24
+ @abstractmethod
25
+ def write_bytes(self, path: str, data: bytes) -> None:
26
+ """Write bytes to file."""
27
+ ...
28
+
29
+ @abstractmethod
30
+ def write_text(self, path: str, data: str, encoding: str = "utf-8") -> None:
31
+ """Write text to file."""
32
+ ...
33
+
34
+ @abstractmethod
35
+ def delete(self, path: str) -> None:
36
+ """Delete file."""
37
+ ...
38
+
39
+ @abstractmethod
40
+ def list_dir(self, path: str) -> Iterator[str]:
41
+ """List directory contents."""
42
+ ...
43
+
44
+ @abstractmethod
45
+ def is_dir(self, path: str) -> bool:
46
+ """Check if path is a directory."""
47
+ ...
48
+
49
+ @abstractmethod
50
+ def is_file(self, path: str) -> bool:
51
+ """Check if path is a file."""
52
+ ...
53
+
54
+ @abstractmethod
55
+ def stat(self, path: str) -> Any:
56
+ """Get file stats."""
57
+ ...
58
+
59
+ @abstractmethod
60
+ def mkdir(self, path: str, parents: bool = False, exist_ok: bool = False) -> None:
61
+ """Create a directory marker (empty blob with trailing slash)."""
62
+ ...
63
+
64
+ @abstractmethod
65
+ def glob(self, path: str, pattern: str) -> Iterator[str]:
66
+ """Find all paths matching pattern."""
67
+ ...
68
+
69
+ @abstractmethod
70
+ def walk(self, path: str) -> Iterator[tuple[str, list[str], list[str]]]:
71
+ """Walk directory tree."""
72
+ ...
73
+
74
+ @abstractmethod
75
+ def touch(self, path: str, exist_ok: bool = True) -> None:
76
+ """Create empty file or update metadata."""
77
+ ...
78
+
79
+ @abstractmethod
80
+ def rename(self, src: str, dst: str) -> None:
81
+ """Rename/move file."""
82
+ ...
83
+
84
+ @abstractmethod
85
+ def rmdir(self, path: str) -> None:
86
+ """Remove directory marker."""
87
+ ...
88
+
89
+ @abstractmethod
90
+ def is_symlink(self, path: str) -> bool:
91
+ """Check if path is a symlink (via metadata)."""
92
+ ...
93
+
94
+ @abstractmethod
95
+ def readlink(self, path: str) -> str:
96
+ """Read symlink target from metadata."""
97
+ ...
98
+
99
+ @abstractmethod
100
+ def symlink_to(self, path: str, target: str) -> None:
101
+ """Create symlink by storing target in metadata."""
102
+ ...
103
+
104
+ @abstractmethod
105
+ def get_metadata(self, path: str) -> dict[str, str]:
106
+ """Get object metadata."""
107
+ ...
108
+
109
+ @abstractmethod
110
+ def set_metadata(self, path: str, metadata: dict[str, str]) -> None:
111
+ """Set object metadata."""
112
+ ...
113
+
114
+ @abstractmethod
115
+ def rmtree(self, path: str, ignore_errors: bool = False, onerror: Optional[Any] = None) -> None:
116
+ """Remove directory and all its contents recursively."""
117
+ ...
118
+
119
+ @abstractmethod
120
+ def copy(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
121
+ """Copy file from src to dst."""
122
+ ...
123
+
124
+ @abstractmethod
125
+ def copytree(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
126
+ """Copy directory tree from src to dst recursively."""
127
+ ...
128
+
129
+ @abstractmethod
130
+ def open(
131
+ self,
132
+ path: str,
133
+ mode: str = "r",
134
+ encoding: Optional[str] = None,
135
+ **kwargs: Any,
136
+ ) -> Union[BinaryIO, TextIO]:
137
+ """Open file for reading/writing."""
138
+ ...
139
+
140
+
141
+ class AsyncClient(ABC):
142
+ """Base class for asynchronous cloud storage clients."""
143
+
144
+ @abstractmethod
145
+ async def exists(self, path: str) -> bool:
146
+ """Check if path exists."""
147
+ ...
148
+
149
+ @abstractmethod
150
+ async def read_bytes(self, path: str) -> bytes:
151
+ """Read file as bytes."""
152
+ ...
153
+
154
+ @abstractmethod
155
+ async def read_text(self, path: str, encoding: str = "utf-8") -> str:
156
+ """Read file as text."""
157
+ ...
158
+
159
+ @abstractmethod
160
+ async def write_bytes(self, path: str, data: bytes) -> None:
161
+ """Write bytes to file."""
162
+ ...
163
+
164
+ @abstractmethod
165
+ async def write_text(self, path: str, data: str, encoding: str = "utf-8") -> None:
166
+ """Write text to file."""
167
+ ...
168
+
169
+ @abstractmethod
170
+ async def delete(self, path: str) -> None:
171
+ """Delete file."""
172
+ ...
173
+
174
+ @abstractmethod
175
+ async def list_dir(self, path: str) -> list[str]:
176
+ """List directory contents."""
177
+ ...
178
+
179
+ @abstractmethod
180
+ async def is_dir(self, path: str) -> bool:
181
+ """Check if path is a directory."""
182
+ ...
183
+
184
+ @abstractmethod
185
+ async def is_file(self, path: str) -> bool:
186
+ """Check if path is a file."""
187
+ ...
188
+
189
+ @abstractmethod
190
+ async def stat(self, path: str) -> Any:
191
+ """Get file stats."""
192
+ ...
193
+
194
+ @abstractmethod
195
+ async def mkdir(self, path: str, parents: bool = False, exist_ok: bool = False) -> None:
196
+ """Create a directory marker (empty blob with trailing slash)."""
197
+ ...
198
+
199
+ @abstractmethod
200
+ async def glob(self, path: str, pattern: str) -> list[str]:
201
+ """Find all paths matching pattern."""
202
+ ...
203
+
204
+ @abstractmethod
205
+ async def walk(self, path: str) -> list[tuple[str, list[str], list[str]]]:
206
+ """Walk directory tree."""
207
+ ...
208
+
209
+ @abstractmethod
210
+ async def touch(self, path: str, exist_ok: bool = True) -> None:
211
+ """Create empty file or update metadata."""
212
+ ...
213
+
214
+ @abstractmethod
215
+ async def rename(self, src: str, dst: str) -> None:
216
+ """Rename/move file."""
217
+ ...
218
+
219
+ @abstractmethod
220
+ async def rmdir(self, path: str) -> None:
221
+ """Remove directory marker."""
222
+ ...
223
+
224
+ @abstractmethod
225
+ async def is_symlink(self, path: str) -> bool:
226
+ """Check if path is a symlink (via metadata)."""
227
+ ...
228
+
229
+ @abstractmethod
230
+ async def readlink(self, path: str) -> str:
231
+ """Read symlink target from metadata."""
232
+ ...
233
+
234
+ @abstractmethod
235
+ async def symlink_to(self, path: str, target: str) -> None:
236
+ """Create symlink by storing target in metadata."""
237
+ ...
238
+
239
+ @abstractmethod
240
+ async def get_metadata(self, path: str) -> dict[str, str]:
241
+ """Get object metadata."""
242
+ ...
243
+
244
+ @abstractmethod
245
+ async def set_metadata(self, path: str, metadata: dict[str, str]) -> None:
246
+ """Set object metadata."""
247
+ ...
248
+
249
+ @abstractmethod
250
+ async def rmtree(self, path: str, ignore_errors: bool = False, onerror: Optional[Any] = None) -> None:
251
+ """Remove directory and all its contents recursively."""
252
+ ...
253
+
254
+ @abstractmethod
255
+ async def copy(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
256
+ """Copy file from src to dst."""
257
+ ...
258
+
259
+ @abstractmethod
260
+ async def copytree(self, src: str, dst: str, follow_symlinks: bool = True) -> None:
261
+ """Copy directory tree from src to dst recursively."""
262
+ ...
263
+
264
+ @abstractmethod
265
+ async def open(
266
+ self,
267
+ path: str,
268
+ mode: str = "r",
269
+ encoding: Optional[str] = None,
270
+ **kwargs: Any,
271
+ ) -> Any: # Returns async file handle
272
+ """Open file for reading/writing."""
273
+ ...
panpath/exceptions.py ADDED
@@ -0,0 +1,38 @@
1
+ """Exception classes for panpath."""
2
+
3
+
4
+ class PanPathError(Exception):
5
+ """Base exception for panpath errors."""
6
+
7
+ pass
8
+
9
+
10
+ class InvalidModeError(PanPathError, ValueError):
11
+ """Raised when an invalid mode is specified."""
12
+
13
+ pass
14
+
15
+
16
+ class MissingDependencyError(PanPathError, ImportError):
17
+ """Raised when a required dependency is not installed."""
18
+
19
+ def __init__(self, backend: str, package: str, extra: str):
20
+ self.backend = backend
21
+ self.package = package
22
+ self.extra = extra
23
+ super().__init__(
24
+ f"The {backend} backend requires '{package}' which is not installed. "
25
+ f"Install it with: pip install panpath[{extra}]"
26
+ )
27
+
28
+
29
+ class CloudPathError(PanPathError):
30
+ """Base exception for cloud path errors."""
31
+
32
+ pass
33
+
34
+
35
+ class NoSuchFileError(CloudPathError, FileNotFoundError):
36
+ """Raised when a cloud file does not exist."""
37
+
38
+ pass
panpath/gs_async.py ADDED
@@ -0,0 +1,20 @@
1
+ """Async Google Cloud Storage path implementation."""
2
+ from typing import TYPE_CHECKING, Optional
3
+
4
+ from panpath.base import AsyncCloudPath
5
+ from panpath.gs_async_client import AsyncGSClient
6
+
7
+ if TYPE_CHECKING:
8
+ from panpath.clients import AsyncClient
9
+
10
+
11
+ class AsyncGSPath(AsyncCloudPath):
12
+ """Asynchronous Google Cloud Storage path implementation."""
13
+
14
+ _client: Optional[AsyncGSClient] = None
15
+ _default_client: Optional[AsyncGSClient] = None
16
+
17
+ @classmethod
18
+ def _create_default_client(cls) -> "AsyncClient":
19
+ """Create default async GCS client."""
20
+ return AsyncGSClient()