panpath 0.1.0__tar.gz
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-0.1.0/LICENSE +21 -0
- panpath-0.1.0/PKG-INFO +256 -0
- panpath-0.1.0/README.md +213 -0
- panpath-0.1.0/panpath/__init__.py +86 -0
- panpath-0.1.0/panpath/azure_async.py +20 -0
- panpath-0.1.0/panpath/azure_async_client.py +551 -0
- panpath-0.1.0/panpath/azure_client.py +542 -0
- panpath-0.1.0/panpath/azure_sync.py +20 -0
- panpath-0.1.0/panpath/base.py +946 -0
- panpath-0.1.0/panpath/clients.py +273 -0
- panpath-0.1.0/panpath/exceptions.py +38 -0
- panpath-0.1.0/panpath/gs_async.py +20 -0
- panpath-0.1.0/panpath/gs_async_client.py +552 -0
- panpath-0.1.0/panpath/gs_client.py +527 -0
- panpath-0.1.0/panpath/gs_sync.py +20 -0
- panpath-0.1.0/panpath/local_async.py +160 -0
- panpath-0.1.0/panpath/local_sync.py +29 -0
- panpath-0.1.0/panpath/py.typed +0 -0
- panpath-0.1.0/panpath/registry.py +71 -0
- panpath-0.1.0/panpath/router.py +174 -0
- panpath-0.1.0/panpath/s3_async.py +20 -0
- panpath-0.1.0/panpath/s3_async_client.py +590 -0
- panpath-0.1.0/panpath/s3_client.py +572 -0
- panpath-0.1.0/panpath/s3_sync.py +23 -0
- panpath-0.1.0/pyproject.toml +93 -0
panpath-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 panpath contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
panpath-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: panpath
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Universal sync/async local/cloud path library with pathlib-compatible interface
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: path,pathlib,s3,gcs,azure,cloud,async,asyncio
|
|
8
|
+
Author: panpath contributors
|
|
9
|
+
Requires-Python: >=3.9,<4.0
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: System :: Filesystems
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Provides-Extra: all-async
|
|
24
|
+
Provides-Extra: all-sync
|
|
25
|
+
Provides-Extra: async-azure
|
|
26
|
+
Provides-Extra: async-gs
|
|
27
|
+
Provides-Extra: async-s3
|
|
28
|
+
Provides-Extra: azure
|
|
29
|
+
Provides-Extra: gs
|
|
30
|
+
Provides-Extra: s3
|
|
31
|
+
Requires-Dist: aioboto3 (>=11.0.0) ; extra == "async-s3" or extra == "all-async" or extra == "all"
|
|
32
|
+
Requires-Dist: aiofiles (>=23.0.0) ; extra == "async-s3" or extra == "async-gs" or extra == "async-azure" or extra == "all-async" or extra == "all"
|
|
33
|
+
Requires-Dist: azure-storage-blob (>=12.0.0) ; extra == "azure" or extra == "async-azure" or extra == "all-sync" or extra == "all-async" or extra == "all"
|
|
34
|
+
Requires-Dist: boto3 (>=1.20.0) ; extra == "s3" or extra == "all-sync" or extra == "all"
|
|
35
|
+
Requires-Dist: gcloud-aio-storage (>=8.0.0) ; extra == "async-gs" or extra == "all-async" or extra == "all"
|
|
36
|
+
Requires-Dist: google-cloud-storage (>=2.0.0) ; extra == "gs" or extra == "all-sync" or extra == "all"
|
|
37
|
+
Requires-Dist: typing-extensions (>=4.0.0)
|
|
38
|
+
Project-URL: Documentation, https://github.com/pwwang/panpath#readme
|
|
39
|
+
Project-URL: Homepage, https://github.com/pwwang/panpath
|
|
40
|
+
Project-URL: Repository, https://github.com/pwwang/panpath
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# PanPath
|
|
44
|
+
|
|
45
|
+
Universal sync/async local/cloud path library with pathlib-compatible interface for Python.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- ๐ **Unified Interface**: Single API for local and cloud storage (S3, Google Cloud Storage, Azure Blob Storage)
|
|
50
|
+
- โก **Sync & Async**: Choose synchronous or asynchronous operations based on your needs
|
|
51
|
+
- ๐ฏ **Pathlib Compatible**: Drop-in replacement for `pathlib.Path` for local files
|
|
52
|
+
- ๐ **Lazy Loading**: Cloud clients instantiated only when needed
|
|
53
|
+
- ๐ **Cross-Storage Operations**: Copy/move files between different storage backends seamlessly
|
|
54
|
+
- ๐ **Bulk Operations**: Efficient `rmtree`, `copy`, `copytree` for directories
|
|
55
|
+
- ๐งช **Testable**: Local mock infrastructure for testing without cloud resources
|
|
56
|
+
- ๐ฆ **Optional Dependencies**: Install only what you need
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Core library (local paths only)
|
|
62
|
+
pip install panpath
|
|
63
|
+
|
|
64
|
+
# With sync S3 support
|
|
65
|
+
pip install panpath[s3]
|
|
66
|
+
|
|
67
|
+
# With async S3 support
|
|
68
|
+
pip install panpath[async-s3]
|
|
69
|
+
|
|
70
|
+
# With all sync backends
|
|
71
|
+
pip install panpath[all-sync]
|
|
72
|
+
|
|
73
|
+
# With all async backends
|
|
74
|
+
pip install panpath[all-async]
|
|
75
|
+
|
|
76
|
+
# With everything
|
|
77
|
+
pip install panpath[all]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quick Start
|
|
81
|
+
|
|
82
|
+
### Synchronous Usage
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from panpath import PanPath
|
|
86
|
+
|
|
87
|
+
# Local files (pathlib.Path compatible)
|
|
88
|
+
local = PanPath("/path/to/file.txt")
|
|
89
|
+
content = local.read_text()
|
|
90
|
+
|
|
91
|
+
# S3 (synchronous)
|
|
92
|
+
s3_file = PanPath("s3://bucket/key/file.txt")
|
|
93
|
+
content = s3_file.read_text()
|
|
94
|
+
|
|
95
|
+
# Google Cloud Storage (synchronous)
|
|
96
|
+
gs_file = PanPath("gs://bucket/path/file.txt")
|
|
97
|
+
content = gs_file.read_text()
|
|
98
|
+
|
|
99
|
+
# Azure Blob Storage (synchronous)
|
|
100
|
+
azure_file = PanPath("az://container/path/file.txt")
|
|
101
|
+
content = azure_file.read_text()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Asynchronous Usage
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from panpath import PanPath, AsyncPanPath
|
|
108
|
+
|
|
109
|
+
# Option 1: Using mode parameter
|
|
110
|
+
async_s3 = PanPath("s3://bucket/key/file.txt", mode="async")
|
|
111
|
+
content = await async_s3.read_text()
|
|
112
|
+
|
|
113
|
+
# Option 2: Using AsyncPanPath (always async)
|
|
114
|
+
async_gs = AsyncPanPath("gs://bucket/path/file.txt")
|
|
115
|
+
content = await async_gs.read_text()
|
|
116
|
+
|
|
117
|
+
# Async local files
|
|
118
|
+
async_local = AsyncPanPath("/path/to/file.txt")
|
|
119
|
+
async with async_local.open("r") as f:
|
|
120
|
+
content = await f.read()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Path Operations
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from panpath import PanPath
|
|
127
|
+
|
|
128
|
+
# Path operations preserve type and mode
|
|
129
|
+
s3_path = PanPath("s3://bucket/data/file.txt")
|
|
130
|
+
parent = s3_path.parent # Returns S3Path (sync)
|
|
131
|
+
sibling = s3_path.parent / "other.txt" # Returns S3Path (sync)
|
|
132
|
+
|
|
133
|
+
# Async paths preserve async mode
|
|
134
|
+
async_path = PanPath("s3://bucket/data/file.txt", mode="async")
|
|
135
|
+
async_parent = async_path.parent # Returns AsyncS3Path
|
|
136
|
+
async_sibling = async_parent / "other.txt" # Returns AsyncS3Path
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Bulk Operations and Cross-Storage Transfers
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from panpath import PanPath
|
|
143
|
+
|
|
144
|
+
# Copy between different cloud providers
|
|
145
|
+
s3_file = PanPath("s3://my-bucket/data.csv")
|
|
146
|
+
s3_file.copy("gs://other-bucket/data.csv") # S3 โ GCS
|
|
147
|
+
|
|
148
|
+
# Download entire directory from cloud
|
|
149
|
+
cloud_dir = PanPath("s3://bucket/dataset/")
|
|
150
|
+
cloud_dir.copytree("/tmp/dataset/") # Downloads all files
|
|
151
|
+
|
|
152
|
+
# Upload local directory to cloud
|
|
153
|
+
local_dir = PanPath("/home/user/project/")
|
|
154
|
+
local_dir.copytree("az://container/project/") # Uploads to Azure
|
|
155
|
+
|
|
156
|
+
# Remove directory recursively
|
|
157
|
+
temp_dir = PanPath("gs://bucket/temp/")
|
|
158
|
+
temp_dir.rmtree() # Deletes all files in temp/
|
|
159
|
+
|
|
160
|
+
# Move between cloud providers (copy + delete)
|
|
161
|
+
s3_data = PanPath("s3://old-bucket/data/")
|
|
162
|
+
s3_data.rename("gs://new-bucket/data/") # Migrates to GCS
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
See [bulk-operations.md](docs/guide/bulk-operations.md) for detailed documentation and examples.
|
|
166
|
+
|
|
167
|
+
## URI Schemes
|
|
168
|
+
|
|
169
|
+
- `file://` or no prefix โ Local filesystem
|
|
170
|
+
- `s3://` โ Amazon S3
|
|
171
|
+
- `gs://` โ Google Cloud Storage
|
|
172
|
+
- `az://` or `azure://` โ Azure Blob Storage
|
|
173
|
+
|
|
174
|
+
## Architecture
|
|
175
|
+
|
|
176
|
+
PanPath uses a metaclass factory pattern to dispatch path creation based on URI scheme and mode parameter:
|
|
177
|
+
|
|
178
|
+
- **Sync Mode**: Returns `LocalPath`, `S3Path`, `GSPath`, or `AzureBlobPath`
|
|
179
|
+
- **Async Mode**: Returns `AsyncLocalPath`, `AsyncS3Path`, `AsyncGSPath`, or `AsyncAzureBlobPath`
|
|
180
|
+
|
|
181
|
+
Cloud paths use lazy client instantiation - SDK clients are only created on first I/O operation.
|
|
182
|
+
|
|
183
|
+
## Type Hints
|
|
184
|
+
|
|
185
|
+
PanPath provides comprehensive type hints with `@overload` decorators:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from panpath import PanPath
|
|
189
|
+
from typing import Literal
|
|
190
|
+
|
|
191
|
+
# Type checker knows return type based on mode
|
|
192
|
+
sync_path: S3Path = PanPath("s3://bucket/key")
|
|
193
|
+
async_path: AsyncS3Path = PanPath("s3://bucket/key", mode="async")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Testing
|
|
197
|
+
|
|
198
|
+
Use local mock infrastructure for testing without cloud credentials:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
import pytest
|
|
202
|
+
from panpath.testing import use_local_mocks
|
|
203
|
+
|
|
204
|
+
@use_local_mocks()
|
|
205
|
+
def test_s3_operations():
|
|
206
|
+
path = PanPath("s3://test-bucket/file.txt")
|
|
207
|
+
path.write_text("test content")
|
|
208
|
+
assert path.read_text() == "test content"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Migration Guide
|
|
212
|
+
|
|
213
|
+
### From pathlib
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
# Before
|
|
217
|
+
from pathlib import Path
|
|
218
|
+
path = Path("/local/file.txt")
|
|
219
|
+
|
|
220
|
+
# After (drop-in replacement)
|
|
221
|
+
from panpath import PanPath
|
|
222
|
+
path = PanPath("/local/file.txt")
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### From cloudpathlib
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
# Before
|
|
229
|
+
from cloudpathlib import S3Path
|
|
230
|
+
path = S3Path("s3://bucket/key")
|
|
231
|
+
|
|
232
|
+
# After
|
|
233
|
+
from panpath import PanPath
|
|
234
|
+
path = PanPath("s3://bucket/key")
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### From aiopath
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
# Before
|
|
241
|
+
from aiopath import AsyncPath
|
|
242
|
+
path = AsyncPath("/local/file.txt")
|
|
243
|
+
|
|
244
|
+
# After
|
|
245
|
+
from panpath import AsyncPanPath
|
|
246
|
+
path = AsyncPanPath("/local/file.txt")
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
MIT License - see LICENSE file for details.
|
|
252
|
+
|
|
253
|
+
## Contributing
|
|
254
|
+
|
|
255
|
+
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
|
|
256
|
+
|
panpath-0.1.0/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# PanPath
|
|
2
|
+
|
|
3
|
+
Universal sync/async local/cloud path library with pathlib-compatible interface for Python.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **Unified Interface**: Single API for local and cloud storage (S3, Google Cloud Storage, Azure Blob Storage)
|
|
8
|
+
- โก **Sync & Async**: Choose synchronous or asynchronous operations based on your needs
|
|
9
|
+
- ๐ฏ **Pathlib Compatible**: Drop-in replacement for `pathlib.Path` for local files
|
|
10
|
+
- ๐ **Lazy Loading**: Cloud clients instantiated only when needed
|
|
11
|
+
- ๐ **Cross-Storage Operations**: Copy/move files between different storage backends seamlessly
|
|
12
|
+
- ๐ **Bulk Operations**: Efficient `rmtree`, `copy`, `copytree` for directories
|
|
13
|
+
- ๐งช **Testable**: Local mock infrastructure for testing without cloud resources
|
|
14
|
+
- ๐ฆ **Optional Dependencies**: Install only what you need
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Core library (local paths only)
|
|
20
|
+
pip install panpath
|
|
21
|
+
|
|
22
|
+
# With sync S3 support
|
|
23
|
+
pip install panpath[s3]
|
|
24
|
+
|
|
25
|
+
# With async S3 support
|
|
26
|
+
pip install panpath[async-s3]
|
|
27
|
+
|
|
28
|
+
# With all sync backends
|
|
29
|
+
pip install panpath[all-sync]
|
|
30
|
+
|
|
31
|
+
# With all async backends
|
|
32
|
+
pip install panpath[all-async]
|
|
33
|
+
|
|
34
|
+
# With everything
|
|
35
|
+
pip install panpath[all]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
### Synchronous Usage
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from panpath import PanPath
|
|
44
|
+
|
|
45
|
+
# Local files (pathlib.Path compatible)
|
|
46
|
+
local = PanPath("/path/to/file.txt")
|
|
47
|
+
content = local.read_text()
|
|
48
|
+
|
|
49
|
+
# S3 (synchronous)
|
|
50
|
+
s3_file = PanPath("s3://bucket/key/file.txt")
|
|
51
|
+
content = s3_file.read_text()
|
|
52
|
+
|
|
53
|
+
# Google Cloud Storage (synchronous)
|
|
54
|
+
gs_file = PanPath("gs://bucket/path/file.txt")
|
|
55
|
+
content = gs_file.read_text()
|
|
56
|
+
|
|
57
|
+
# Azure Blob Storage (synchronous)
|
|
58
|
+
azure_file = PanPath("az://container/path/file.txt")
|
|
59
|
+
content = azure_file.read_text()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Asynchronous Usage
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from panpath import PanPath, AsyncPanPath
|
|
66
|
+
|
|
67
|
+
# Option 1: Using mode parameter
|
|
68
|
+
async_s3 = PanPath("s3://bucket/key/file.txt", mode="async")
|
|
69
|
+
content = await async_s3.read_text()
|
|
70
|
+
|
|
71
|
+
# Option 2: Using AsyncPanPath (always async)
|
|
72
|
+
async_gs = AsyncPanPath("gs://bucket/path/file.txt")
|
|
73
|
+
content = await async_gs.read_text()
|
|
74
|
+
|
|
75
|
+
# Async local files
|
|
76
|
+
async_local = AsyncPanPath("/path/to/file.txt")
|
|
77
|
+
async with async_local.open("r") as f:
|
|
78
|
+
content = await f.read()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Path Operations
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from panpath import PanPath
|
|
85
|
+
|
|
86
|
+
# Path operations preserve type and mode
|
|
87
|
+
s3_path = PanPath("s3://bucket/data/file.txt")
|
|
88
|
+
parent = s3_path.parent # Returns S3Path (sync)
|
|
89
|
+
sibling = s3_path.parent / "other.txt" # Returns S3Path (sync)
|
|
90
|
+
|
|
91
|
+
# Async paths preserve async mode
|
|
92
|
+
async_path = PanPath("s3://bucket/data/file.txt", mode="async")
|
|
93
|
+
async_parent = async_path.parent # Returns AsyncS3Path
|
|
94
|
+
async_sibling = async_parent / "other.txt" # Returns AsyncS3Path
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Bulk Operations and Cross-Storage Transfers
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from panpath import PanPath
|
|
101
|
+
|
|
102
|
+
# Copy between different cloud providers
|
|
103
|
+
s3_file = PanPath("s3://my-bucket/data.csv")
|
|
104
|
+
s3_file.copy("gs://other-bucket/data.csv") # S3 โ GCS
|
|
105
|
+
|
|
106
|
+
# Download entire directory from cloud
|
|
107
|
+
cloud_dir = PanPath("s3://bucket/dataset/")
|
|
108
|
+
cloud_dir.copytree("/tmp/dataset/") # Downloads all files
|
|
109
|
+
|
|
110
|
+
# Upload local directory to cloud
|
|
111
|
+
local_dir = PanPath("/home/user/project/")
|
|
112
|
+
local_dir.copytree("az://container/project/") # Uploads to Azure
|
|
113
|
+
|
|
114
|
+
# Remove directory recursively
|
|
115
|
+
temp_dir = PanPath("gs://bucket/temp/")
|
|
116
|
+
temp_dir.rmtree() # Deletes all files in temp/
|
|
117
|
+
|
|
118
|
+
# Move between cloud providers (copy + delete)
|
|
119
|
+
s3_data = PanPath("s3://old-bucket/data/")
|
|
120
|
+
s3_data.rename("gs://new-bucket/data/") # Migrates to GCS
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
See [bulk-operations.md](docs/guide/bulk-operations.md) for detailed documentation and examples.
|
|
124
|
+
|
|
125
|
+
## URI Schemes
|
|
126
|
+
|
|
127
|
+
- `file://` or no prefix โ Local filesystem
|
|
128
|
+
- `s3://` โ Amazon S3
|
|
129
|
+
- `gs://` โ Google Cloud Storage
|
|
130
|
+
- `az://` or `azure://` โ Azure Blob Storage
|
|
131
|
+
|
|
132
|
+
## Architecture
|
|
133
|
+
|
|
134
|
+
PanPath uses a metaclass factory pattern to dispatch path creation based on URI scheme and mode parameter:
|
|
135
|
+
|
|
136
|
+
- **Sync Mode**: Returns `LocalPath`, `S3Path`, `GSPath`, or `AzureBlobPath`
|
|
137
|
+
- **Async Mode**: Returns `AsyncLocalPath`, `AsyncS3Path`, `AsyncGSPath`, or `AsyncAzureBlobPath`
|
|
138
|
+
|
|
139
|
+
Cloud paths use lazy client instantiation - SDK clients are only created on first I/O operation.
|
|
140
|
+
|
|
141
|
+
## Type Hints
|
|
142
|
+
|
|
143
|
+
PanPath provides comprehensive type hints with `@overload` decorators:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from panpath import PanPath
|
|
147
|
+
from typing import Literal
|
|
148
|
+
|
|
149
|
+
# Type checker knows return type based on mode
|
|
150
|
+
sync_path: S3Path = PanPath("s3://bucket/key")
|
|
151
|
+
async_path: AsyncS3Path = PanPath("s3://bucket/key", mode="async")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Testing
|
|
155
|
+
|
|
156
|
+
Use local mock infrastructure for testing without cloud credentials:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
import pytest
|
|
160
|
+
from panpath.testing import use_local_mocks
|
|
161
|
+
|
|
162
|
+
@use_local_mocks()
|
|
163
|
+
def test_s3_operations():
|
|
164
|
+
path = PanPath("s3://test-bucket/file.txt")
|
|
165
|
+
path.write_text("test content")
|
|
166
|
+
assert path.read_text() == "test content"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Migration Guide
|
|
170
|
+
|
|
171
|
+
### From pathlib
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
# Before
|
|
175
|
+
from pathlib import Path
|
|
176
|
+
path = Path("/local/file.txt")
|
|
177
|
+
|
|
178
|
+
# After (drop-in replacement)
|
|
179
|
+
from panpath import PanPath
|
|
180
|
+
path = PanPath("/local/file.txt")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### From cloudpathlib
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
# Before
|
|
187
|
+
from cloudpathlib import S3Path
|
|
188
|
+
path = S3Path("s3://bucket/key")
|
|
189
|
+
|
|
190
|
+
# After
|
|
191
|
+
from panpath import PanPath
|
|
192
|
+
path = PanPath("s3://bucket/key")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### From aiopath
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
# Before
|
|
199
|
+
from aiopath import AsyncPath
|
|
200
|
+
path = AsyncPath("/local/file.txt")
|
|
201
|
+
|
|
202
|
+
# After
|
|
203
|
+
from panpath import AsyncPanPath
|
|
204
|
+
path = AsyncPanPath("/local/file.txt")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT License - see LICENSE file for details.
|
|
210
|
+
|
|
211
|
+
## Contributing
|
|
212
|
+
|
|
213
|
+
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""PanPath - Universal sync/async local/cloud path library.
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
>>> from panpath import PanPath, AsyncPanPath
|
|
5
|
+
>>>
|
|
6
|
+
>>> # Sync local path
|
|
7
|
+
>>> path = PanPath("/path/to/file.txt")
|
|
8
|
+
>>> content = path.read_text()
|
|
9
|
+
>>>
|
|
10
|
+
>>> # Sync S3 path
|
|
11
|
+
>>> s3_path = PanPath("s3://bucket/key.txt")
|
|
12
|
+
>>> content = s3_path.read_text()
|
|
13
|
+
>>>
|
|
14
|
+
>>> # Async S3 path
|
|
15
|
+
>>> async_path = PanPath("s3://bucket/key.txt", mode="async")
|
|
16
|
+
>>> content = await async_path.read_text()
|
|
17
|
+
>>>
|
|
18
|
+
>>> # AsyncPanPath (always async)
|
|
19
|
+
>>> async_path = AsyncPanPath("s3://bucket/key.txt")
|
|
20
|
+
>>> content = await async_path.read_text()
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from panpath.router import AsyncPanPath, PanPath
|
|
24
|
+
from panpath.local_sync import LocalPath
|
|
25
|
+
from panpath.local_async import AsyncLocalPath
|
|
26
|
+
|
|
27
|
+
# Import path classes and register them
|
|
28
|
+
from panpath.registry import register_path_class
|
|
29
|
+
|
|
30
|
+
# Register S3
|
|
31
|
+
try:
|
|
32
|
+
from panpath.s3_sync import S3Path
|
|
33
|
+
from panpath.s3_async import AsyncS3Path
|
|
34
|
+
|
|
35
|
+
register_path_class("s3", S3Path, AsyncS3Path)
|
|
36
|
+
except ImportError:
|
|
37
|
+
# S3 dependencies not installed
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
# Register Google Cloud Storage
|
|
41
|
+
try:
|
|
42
|
+
from panpath.gs_sync import GSPath
|
|
43
|
+
from panpath.gs_async import AsyncGSPath
|
|
44
|
+
|
|
45
|
+
register_path_class("gs", GSPath, AsyncGSPath)
|
|
46
|
+
except ImportError:
|
|
47
|
+
# GCS dependencies not installed
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
# Register Azure Blob Storage
|
|
51
|
+
try:
|
|
52
|
+
from panpath.azure_sync import AzureBlobPath
|
|
53
|
+
from panpath.azure_async import AsyncAzureBlobPath
|
|
54
|
+
|
|
55
|
+
register_path_class("az", AzureBlobPath, AsyncAzureBlobPath)
|
|
56
|
+
register_path_class("azure", AzureBlobPath, AsyncAzureBlobPath) # Support both schemes
|
|
57
|
+
except ImportError:
|
|
58
|
+
# Azure dependencies not installed
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
__version__ = "0.1.0"
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
"PanPath",
|
|
65
|
+
"AsyncPanPath",
|
|
66
|
+
"LocalPath",
|
|
67
|
+
"AsyncLocalPath",
|
|
68
|
+
# Export cloud paths if available
|
|
69
|
+
# Users can import specific classes if needed
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
# Add cloud path classes to __all__ if they're available
|
|
73
|
+
try:
|
|
74
|
+
__all__.extend(["S3Path", "AsyncS3Path"])
|
|
75
|
+
except NameError:
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
__all__.extend(["GSPath", "AsyncGSPath"])
|
|
80
|
+
except NameError:
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
__all__.extend(["AzureBlobPath", "AsyncAzureBlobPath"])
|
|
85
|
+
except NameError:
|
|
86
|
+
pass
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Async Azure Blob Storage path implementation."""
|
|
2
|
+
from typing import TYPE_CHECKING, Optional
|
|
3
|
+
|
|
4
|
+
from panpath.base import AsyncCloudPath
|
|
5
|
+
from panpath.azure_async_client import AsyncAzureBlobClient
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from panpath.clients import AsyncClient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AsyncAzureBlobPath(AsyncCloudPath):
|
|
12
|
+
"""Asynchronous Azure Blob Storage path implementation."""
|
|
13
|
+
|
|
14
|
+
_client: Optional[AsyncAzureBlobClient] = None
|
|
15
|
+
_default_client: Optional[AsyncAzureBlobClient] = None
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def _create_default_client(cls) -> "AsyncClient":
|
|
19
|
+
"""Create default async Azure Blob client."""
|
|
20
|
+
return AsyncAzureBlobClient()
|