Universal sync/async local/cloud path library with pathlib-compatible interface
Project description
PanPath
Universal sync/async local/cloud path library with pathlib-compatible interface for Python.
Features
- 🔄 Unified Interface: Single API for local and cloud storage (S3, Google Cloud Storage, Azure Blob Storage)
- ⚡ Sync & Async: Choose synchronous or asynchronous operations based on your needs
- 🎯 Pathlib Compatible: Drop-in replacement for
pathlib.Pathfor local files - 🔌 Lazy Loading: Cloud clients instantiated only when needed
- 🌐 Cross-Storage Operations: Copy/move files between different storage backends seamlessly
- 📁 Bulk Operations: Efficient
rmtree,copy,copytreefor directories - 🧪 Testable: Local mock infrastructure for testing without cloud resources
- 📦 Optional Dependencies: Install only what you need
Installation
# Core library (local paths only)
pip install panpath
# With sync S3 support
pip install panpath[s3]
# With async S3 support
pip install panpath[async-s3]
# With all sync backends
pip install panpath[all-sync]
# With all async backends
pip install panpath[all-async]
# With everything
pip install panpath[all]
Quick Start
Synchronous Usage
from panpath import PanPath
# Local files (pathlib.Path compatible)
local = PanPath("/path/to/file.txt")
content = local.read_text()
# S3 (synchronous)
s3_file = PanPath("s3://bucket/key/file.txt")
content = s3_file.read_text()
# Google Cloud Storage (synchronous)
gs_file = PanPath("gs://bucket/path/file.txt")
content = gs_file.read_text()
# Azure Blob Storage (synchronous)
azure_file = PanPath("az://container/path/file.txt")
content = azure_file.read_text()
Asynchronous Usage
from panpath import PanPath, AsyncPanPath
# Option 1: Using mode parameter
async_s3 = PanPath("s3://bucket/key/file.txt", mode="async")
content = await async_s3.read_text()
# Option 2: Using AsyncPanPath (always async)
async_gs = AsyncPanPath("gs://bucket/path/file.txt")
content = await async_gs.read_text()
# Async local files
async_local = AsyncPanPath("/path/to/file.txt")
async with async_local.open("r") as f:
content = await f.read()
Path Operations
from panpath import PanPath
# Path operations preserve type and mode
s3_path = PanPath("s3://bucket/data/file.txt")
parent = s3_path.parent # Returns S3Path (sync)
sibling = s3_path.parent / "other.txt" # Returns S3Path (sync)
# Async paths preserve async mode
async_path = PanPath("s3://bucket/data/file.txt", mode="async")
async_parent = async_path.parent # Returns AsyncS3Path
async_sibling = async_parent / "other.txt" # Returns AsyncS3Path
Bulk Operations and Cross-Storage Transfers
from panpath import PanPath
# Copy between different cloud providers
s3_file = PanPath("s3://my-bucket/data.csv")
s3_file.copy("gs://other-bucket/data.csv") # S3 → GCS
# Download entire directory from cloud
cloud_dir = PanPath("s3://bucket/dataset/")
cloud_dir.copytree("/tmp/dataset/") # Downloads all files
# Upload local directory to cloud
local_dir = PanPath("/home/user/project/")
local_dir.copytree("az://container/project/") # Uploads to Azure
# Remove directory recursively
temp_dir = PanPath("gs://bucket/temp/")
temp_dir.rmtree() # Deletes all files in temp/
# Move between cloud providers (copy + delete)
s3_data = PanPath("s3://old-bucket/data/")
s3_data.rename("gs://new-bucket/data/") # Migrates to GCS
See bulk-operations.md for detailed documentation and examples.
URI Schemes
file://or no prefix → Local filesystems3://→ Amazon S3gs://→ Google Cloud Storageaz://orazure://→ Azure Blob Storage
Architecture
PanPath uses a metaclass factory pattern to dispatch path creation based on URI scheme and mode parameter:
- Sync Mode: Returns
LocalPath,S3Path,GSPath, orAzureBlobPath - Async Mode: Returns
AsyncLocalPath,AsyncS3Path,AsyncGSPath, orAsyncAzureBlobPath
Cloud paths use lazy client instantiation - SDK clients are only created on first I/O operation.
Type Hints
PanPath provides comprehensive type hints with @overload decorators:
from panpath import PanPath
from typing import Literal
# Type checker knows return type based on mode
sync_path: S3Path = PanPath("s3://bucket/key")
async_path: AsyncS3Path = PanPath("s3://bucket/key", mode="async")
Testing
Use local mock infrastructure for testing without cloud credentials:
import pytest
from panpath.testing import use_local_mocks
@use_local_mocks()
def test_s3_operations():
path = PanPath("s3://test-bucket/file.txt")
path.write_text("test content")
assert path.read_text() == "test content"
Migration Guide
From pathlib
# Before
from pathlib import Path
path = Path("/local/file.txt")
# After (drop-in replacement)
from panpath import PanPath
path = PanPath("/local/file.txt")
From cloudpathlib
# Before
from cloudpathlib import S3Path
path = S3Path("s3://bucket/key")
# After
from panpath import PanPath
path = PanPath("s3://bucket/key")
From aiopath
# Before
from aiopath import AsyncPath
path = AsyncPath("/local/file.txt")
# After
from panpath import AsyncPanPath
path = AsyncPanPath("/local/file.txt")
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file panpath-0.1.0.tar.gz.
File metadata
- Download URL: panpath-0.1.0.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8939ce50d517c1f6099b5977a4e172117239610aef3e8dc399a56f43f10ce231
|
|
| MD5 |
cb0701b0a7a0e19c7a3f5346881e4e29
|
|
| BLAKE2b-256 |
16e01a455a9f9d15422fee61cf11597d989e84b497afa59f2c87869f9000f889
|
File details
Details for the file panpath-0.1.0-py3-none-any.whl.
File metadata
- Download URL: panpath-0.1.0-py3-none-any.whl
- Upload date:
- Size: 44.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ab802e26b7a1847a5ae7cd7f97506e466b9bd4e584babfe4d2cb92a97f7dbbe
|
|
| MD5 |
4873ef138e76c4765ed39b1381695704
|
|
| BLAKE2b-256 |
76d31c94d26783395066510e047ca9541211d74e44ae56f150f8fd21cdac1820
|