Migration from cloudpathlib¶
This guide helps you migrate from cloudpathlib to PanPath.
Why Migrate?¶
PanPath offers several advantages over cloudpathlib:
- ✅ Local path support - Same API for local and cloud storage
- ✅ Explicit async/sync - Clear separation with better type safety
- ✅ Better performance - Lazy client loading and optimized operations
- ✅ Cross-storage operations - Copy/move between different providers
- ✅ Simpler API - Unified
PanPathinstead of separate classes
Compatibility¶
PanPath maintains compatibility with most cloudpathlib features. See Cloudpathlib Compatibility for detailed comparison.
Quick Migration Guide¶
Installation¶
cloudpathlib:
PanPath:
Basic Path Creation¶
Reading and Writing¶
The API is identical:
Path Operations¶
Most operations are identical:
Directory Operations¶
Key Differences¶
1. Async Support¶
cloudpathlib has async support mixed into the same classes.
PanPath has explicit sync/async separation:
2. Local Paths¶
cloudpathlib doesn't support local paths.
PanPath treats local paths the same as cloud paths:
3. Client Configuration¶
cloudpathlib uses client objects.
PanPath uses lazy client creation with registry:
4. File Caching¶
cloudpathlib has built-in file caching.
PanPath doesn't implement caching (yet):
Migration Steps¶
Step 1: Update Imports¶
Replace cloudpathlib imports:
Step 2: Update Path Creation¶
Replace specific path classes with PanPath:
# Before
s3 = S3Path("s3://bucket/key")
gs = GSPath("gs://bucket/path")
# After
s3 = PanPath("s3://bucket/key")
gs = PanPath("gs://bucket/path")
Step 3: Update Client Configuration¶
If you use custom clients:
# Before
from cloudpathlib import S3Client, S3Path
client = S3Client(...)
path = S3Path("s3://bucket/key", client=client)
# After
from panpath import PanPath
from panpath.clients import get_s3_client
get_s3_client(...) # Configure once
path = PanPath("s3://bucket/key") # Uses configured client
Step 4: Update Async Code¶
Make async operations explicit:
# Before
from cloudpathlib import CloudPath
path = CloudPath("s3://bucket/file.txt")
# Might be async internally?
# After
from panpath import PanPath
async_path = PanPath("s3://bucket/file.txt")
content = await async_path.a_read_text()
Step 5: Remove Caching Code¶
If you relied on automatic caching:
# Before
from cloudpathlib import S3Path
path = S3Path("s3://bucket/file.txt")
local_path = path.fspath # Cached local copy
# After
from panpath import PanPath
path = PanPath("s3://bucket/file.txt")
# Download explicitly if needed
local_path = "/tmp/file.txt"
path.copy(local_path)
Complete Example¶
Here's a complete migration example:
from cloudpathlib import CloudPath, S3Client
# Configure client
client = S3Client(
aws_access_key_id="key",
aws_secret_access_key="secret"
)
# Process files
def process_files(bucket_uri: str):
directory = CloudPath(bucket_uri, client=client)
for txt_file in directory.glob("*.txt"):
content = txt_file.read_text()
# Process content
processed = content.upper()
# Write to new location
output = txt_file.with_stem(f"{txt_file.stem}_processed")
output.write_text(processed)
process_files("s3://my-bucket/data/")
from panpath import PanPath
from panpath.clients import get_s3_client
# Configure client (optional - uses env vars by default)
get_s3_client(
aws_access_key_id="key",
aws_secret_access_key="secret"
)
# Process files
def process_files(bucket_uri: str):
directory = PanPath(bucket_uri)
for txt_file in directory.glob("*.txt"):
content = txt_file.read_text()
# Process content
processed = content.upper()
# Write to new location
output = txt_file.with_stem(f"{txt_file.stem}_processed")
output.write_text(processed)
process_files("s3://my-bucket/data/")
Testing¶
Mocking¶
PanPath uses a different mocking strategy:
Compatibility Layer¶
If you need to maintain compatibility with both libraries:
def get_cloud_path(uri: str):
"""Get cloud path using available library."""
try:
from panpath import PanPath
return PanPath(uri)
except ImportError:
from cloudpathlib import CloudPath
return CloudPath(uri)
# Use it
path = get_cloud_path("s3://bucket/file.txt")
content = path.read_text()
Next Steps¶
- Quick Start - Learn PanPath basics
- User Guide - Detailed feature documentation
- API Reference - Complete API documentation
- Cloudpathlib Compatibility - Detailed compatibility info