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
# All path classes support async methods with a_ prefix
s3_path = PanPath("s3://bucket/key/file.txt")
content = await s3_path.a_read_text()
# Works for all cloud storage providers
gs_path = PanPath("gs://bucket/path/file.txt")
content = await gs_path.a_read_text()
# Async local files
local_path = PanPath("/path/to/file.txt")
async with local_path.a_open("r") as f:
content = await f.read()
Path Operations
from panpath import PanPath
# Path operations preserve type
s3_path = PanPath("s3://bucket/data/file.txt")
parent = s3_path.parent # Returns S3Path
sibling = s3_path.parent / "other.txt" # Returns S3Path
# Each path supports both sync and async methods
content = s3_path.read_text() # Synchronous
content = await s3_path.a_read_text() # Asynchronous
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 factory pattern to dispatch path creation based on URI scheme:
PanPath(pathlib.Path)- Root factory and base classLocalPath(PanPath)- Local filesystem pathsCloudPath(PanPath)- Base for all cloud storage pathsGSPath(CloudPath),S3Path(CloudPath),AzurePath(CloudPath)- Cloud-specific implementations
Each path class provides both synchronous methods and asynchronous methods (prefixed with a_). Cloud paths use lazy client instantiation - SDK clients are only created on first I/O operation.
Type Hints
PanPath provides comprehensive type hints:
from panpath import PanPath
from panpath.s3_path import S3Path
# Type checker knows return type based on URI scheme
path: S3Path = PanPath("s3://bucket/key")
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")
# await path.read_text()
# After
from panpath import PanPath
path = PanPath("/local/file.txt")
# await path.a_read_text()
License
MIT License - see LICENSE file for details.
Metadata
Release files for panpath 0.4.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| panpath-0.4.12.tar.gz | 521.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| panpath-0.4.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 586.2 kB
Release files / panpath-0.4.12.tar.gz
| Download URL | panpath-0.4.12.tar.gz |
|---|---|
| Size | 521.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2165116e09c1056f474aa4e062d38d2b9f176429cc1d5a6fac578c10f4b6484b
|
|
BLAKE2b-256 checksum How to use checksums |
9ac624a5da9cc39176b4e44faffc47fa837bb047e22d1412a195a88c455e6900
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / panpath-0.4.12-py3-none-any.whl
| Download URL | panpath-0.4.12-py3-none-any.whl |
|---|---|
| Size | 64.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2282bf4e6db9e9a0b394c0fd7c63d5c3556c22616b756b07e699eaedd3d96e21
|
|
BLAKE2b-256 checksum How to use checksums |
a724410cef597b6a2fb16c0d7c1081e0c62ad6c94996086bb7796c3fe387747a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|