Skip to content

UPathTools

UPathTools is a Python library that extends UPath and fsspec with powerful async capabilities, improved type safety, and a collection of specialized filesystem implementations.

Key Features

🚀 Async-First Design

  • AsyncUPath: Fully async path operations with aread_bytes(), awrite_text(), aiterdir(), etc.
  • Async filesystem operations: Batch file reading with configurable parallelism
  • Automatic fallback: Thread-pool execution for filesystems without native async support

🎯 Type Safety

  • Generic filesystem base classes with typed info dictionaries / UPath subclasses
  • Type-safe path classes specific to each filesystem
  • Proper overloads for detail/non-detail variants of operations

📦 Specialized Filesystems

  • File contents as filesystems: Markdown sections, SQLite tables, tree-sitter code structure, OpenAPI / JSON Schema specs
  • Python introspection: installed packages, distributions, Pydantic models and instances
  • Aggregation: union (mount points), flat union, overlay and delegating filesystems
  • Remote: HTTP (httpx2), GitHub Gists / Issues / Wiki, GitLab, Linear, Notion, Appwrite, MCP resources and tools
  • Sandboxes: E2B, Modal, Daytona, Beam, Vercel, Cloudflare, Microsandbox, HopX, Sprites, Codex, SRT

🛠️ Utility Functions

  • Async batch operations: read_folder(), list_files(), read_folder_as_text()
  • Path helpers: to_upath(), upath_to_fs(), type conversions
  • Tree visualization: Rich directory tree rendering
  • Shell-like commands: path.cli("grep TODO . -r") on any BaseUPath / filesystem
  • Configs: Pydantic models for all filesystems in upathtools_config (see Configs)

Quick Start

Basic Usage

from upathtools import AsyncUPath
import asyncio

async def main():
    # Read a file asynchronously
    path = AsyncUPath("https://example.com/data.json")
    content = await path.aread_text()

    # Iterate directory contents
    async for item in AsyncUPath("src/").aiterdir():
        print(item)

asyncio.run(main())

Batch File Operations

from upathtools import read_folder
import asyncio

async def main():
    # Read all Python files in parallel
    files = await read_folder(
        "src/",
        pattern="**/*.py",
        load_parallel=True,
        chunk_size=50
    )

    for filepath, content in files.items():
        print(f"{filepath}: {len(content)} bytes")

asyncio.run(main())

Generic base classes with full typing

UPathTools provides:

from typing import TypedDict

from upathtools.filesystems.base import BaseAsyncFileSystem, BaseUPath


class MyInfoDict(TypedDict):
    name: str
    size: int
    type: str


class MyPath(BaseUPath[MyInfoDict]):
    pass


class MyFileSystem(BaseAsyncFileSystem[MyPath, MyInfoDict]):
    """Fully typed filesystem with custom info structure."""

    protocol = "my"
    upath_cls = MyPath

    async def _ls(self, path: str, detail: bool = True) -> list[MyInfoDict]:
        # Return typed info dictionaries
        ...

Installation

uv add upathtools

# Optional backends are extras, e.g.
uv add "upathtools[httpx,sqlite,mcp]"

Extras

Name Dependencies Description
adlfs adlfs ADLS integration
appwrite appwrite>=16 Appwrite integration (typed models since 16)
beam beam-client>=0.2.187; sys_platform != 'win32' or python_version < '3.14' Beam integration
cloudflare httpx2>=2.16 Cloudflare Sandbox integration
codex codexed Codex CLI integration
daytona daytona<2; python_version < '3.14' Daytona integration
e2b e2b-code-interpreter E2B integration
gcsfs gcsfs GCS integration
gitlab python-gitlab>=7.0.0 GitLab integration
hopx hopx-ai HopX integration
httpx httpx2>=2.16, yarl, brotli httpx2 based filesystem (httpx:// protocol)
httpx2 httpx2>=2.16, yarl, brotli alias of the httpx extra
huggingface_hub huggingface_hub HuggingFace integration
jq jq>=1.8.0 jq JSON processor
jsonschema PyYAML, requests JSON Schema integration
mcp fastmcp, mcp Virtual MCP Tools & MCP Resources filesystem
microsandbox microsandbox; sys_platform != 'win32' Microsandbox integration
modal modal Modal integration
monty pydantic-monty>=0.0.5
notion-client notion-client Notion integration
openapi3 openapi3 OpenAPI integration
s3fs s3fs S3 integration
sprites httpx2>=2.16 Sprites (Fly.io) integration
sqlite sqlalchemy[aiosqlite] SQLite integration
srt anyenv>=2.0.0 Sandbox Runtime (srt) integration
ssh sshfs[bcrypt]>=2025.11.0
tree-sitter tree-sitter>=0.25.2, tree-sitter-python>=0.25.0, tree-sitter-c>=0.24.1, tree-sitter-javascript>=0.25.0, tree-sitter>=0.25.2, tree-sitter-typescript>=0.23.0, tree-sitter-cpp>=0.23.0, tree-sitter-rust>=0.23.0, tree-sitter-go>=0.23.0, tree-sitter-json>=0.24.0, tree-sitter-yaml>=0.6.0 Tree-sitter based filesystem
vercel vercel Vercel integration
webdav4 webdav4 WebDAV integration

Package Overview

📂 upathtools
┣━━ 📂 filesystems
┃   ┣━━ 📂 base
┃   ┃   ┣━━ 🐍 __init__.py (1.0 kB)
┃   ┃   ┣━━ 🐍 archive.py (2.7 kB)
┃   ┃   ┣━━ 🐍 basefilesystem.py (41.3 kB)
┃   ┃   ┣━━ 🐍 baseupath.py (17.0 kB)
┃   ┃   ┣━━ 🐍 cli_helpers.py (4.6 kB)
┃   ┃   ┣━━ 🐍 file_objects.py (10.2 kB)
┃   ┃   ┣━━ 🐍 filefilesystem.py (7.1 kB)
┃   ┃   ┣━━ 🐍 protocols.py (890 Bytes)
┃   ┃   ┗━━ 🐍 wrapper.py (29.5 kB)
┃   ┣━━ 📂 combining_filesystems
┃   ┃   ┣━━ 🐍 __init__.py (481 Bytes)
┃   ┃   ┣━━ 🐍 flat_union_fs.py (19.2 kB)
┃   ┃   ┣━━ 🐍 overlay_fs.py (13.1 kB)
┃   ┃   ┗━━ 🐍 union_fs.py (13.7 kB)
┃   ┣━━ 📂 file_filesystems
┃   ┃   ┣━━ 🐍 __init__.py (1.5 kB)
┃   ┃   ┣━━ 🐍 jsonschema_fs.py (31.4 kB)
┃   ┃   ┣━━ 🐍 markdown_fs.py (11.5 kB)
┃   ┃   ┣━━ 🐍 openapi_fs.py (38.8 kB)
┃   ┃   ┣━━ 🐍 sqlite_fs.py (21.7 kB)
┃   ┃   ┣━━ 🐍 tar_fs.py (4.3 kB)
┃   ┃   ┗━━ 🐍 treesitter_fs.py (19.7 kB)
┃   ┣━━ 📂 fsspec_filesystems
┃   ┃   ┣━━ 🐍 __init__.py (2.4 kB)
┃   ┃   ┣━━ 🐍 azure.py (438 Bytes)
┃   ┃   ┣━━ 🐍 gcs.py (404 Bytes)
┃   ┃   ┣━━ 🐍 hdfs.py (403 Bytes)
┃   ┃   ┣━━ 🐍 hf.py (407 Bytes)
┃   ┃   ┣━━ 🐍 s3.py (363 Bytes)
┃   ┃   ┣━━ 🐍 sftp.py (388 Bytes)
┃   ┃   ┣━━ 🐍 smb.py (380 Bytes)
┃   ┃   ┣━━ 🐍 ssh.py (7.2 kB)
┃   ┃   ┗━━ 🐍 webdav.py (394 Bytes)
┃   ┣━━ 📂 remote_filesystems
┃   ┃   ┣━━ 🐍 __init__.py (714 Bytes)
┃   ┃   ┣━━ 🐍 appwrite_fs.py (30.8 kB)
┃   ┃   ┣━━ 🐍 gist_fs.py (29.3 kB)
┃   ┃   ┣━━ 🐍 github_fs.py (16.7 kB)
┃   ┃   ┣━━ 🐍 gitlab_fs.py (12.6 kB)
┃   ┃   ┣━━ 🐍 issue_fs.py (20.5 kB)
┃   ┃   ┣━━ 🐍 linear_fs.py (47.0 kB)
┃   ┃   ┣━━ 🐍 mcp_fs.py (12.4 kB)
┃   ┃   ┣━━ 🐍 mcp_tools_fs.py (16.3 kB)
┃   ┃   ┣━━ 🐍 notion_fs.py (18.8 kB)
┃   ┃   ┗━━ 🐍 wiki_fs.py (22.2 kB)
┃   ┣━━ 📂 sandbox_filesystems
┃   ┃   ┣━━ 🐍 __init__.py (2.0 kB)
┃   ┃   ┣━━ 🐍 _shell_search.py (6.4 kB)
┃   ┃   ┣━━ 🐍 beam_fs.py (19.6 kB)
┃   ┃   ┣━━ 🐍 cloudflare_fs.py (16.6 kB)
┃   ┃   ┣━━ 🐍 codex_fs.py (11.3 kB)
┃   ┃   ┣━━ 🐍 daytona_fs.py (19.5 kB)
┃   ┃   ┣━━ 🐍 e2b_fs.py (18.3 kB)
┃   ┃   ┣━━ 🐍 hopx_fs.py (14.6 kB)
┃   ┃   ┣━━ 🐍 microsandbox_fs.py (11.9 kB)
┃   ┃   ┣━━ 🐍 modal_fs.py (11.2 kB)
┃   ┃   ┣━━ 🐍 pyodide_fs.py (9.1 kB)
┃   ┃   ┣━━ 📜 pyodide_server.ts (20.4 kB)
┃   ┃   ┣━━ 🐍 sprites_fs.py (15.0 kB)
┃   ┃   ┣━━ 🐍 srt_fs.py (12.0 kB)
┃   ┃   ┗━━ 🐍 vercel_fs.py (14.4 kB)
┃   ┣━━ 🐍 __init__.py (4.0 kB)
┃   ┣━━ 🐍 async_local_fs.py (15.4 kB)
┃   ┣━━ 🐍 auto_expand_fs.py (15.7 kB)
┃   ┣━━ 🐍 basemodel_fs.py (19.0 kB)
┃   ┣━━ 🐍 basemodel_instance_fs.py (20.0 kB)
┃   ┣━━ 🐍 delegating_fs.py (19.6 kB)
┃   ┣━━ 🐍 distribution_fs.py (6.6 kB)
┃   ┣━━ 🐍 httpx_fs.py (35.2 kB)
┃   ┣━━ 🐍 isolated_memory_fs.py (4.8 kB)
┃   ┣━━ 🐍 package_fs.py (7.9 kB)
┃   ┗━━ 🐍 skills_fs.py (4.4 kB)
┣━━ 📂 filetree
┃   ┣━━ 🐍 __init__.py (474 Bytes)
┃   ┣━━ 🐍 data.py (2.1 kB)
┃   ┣━━ 🐍 file_icons.py (18.8 kB)
┃   ┗━━ 🐍 filetree.py (13.2 kB)
┣━━ 🐍 __init__.py (3.1 kB)
┣━━ 🐍 async_helpers.py (5.1 kB)
┣━━ 🐍 async_ops.py (21.3 kB)
┣━━ 🐍 async_upath.py (8.6 kB)
┣━━ 🐍 cli_ops.py (28.3 kB)
┣━━ 🐍 cli_parser.py (6.9 kB)
┣━━ 🐍 common_types.py (256 Bytes)
┣━━ 🐍 core.py (2.9 kB)
┣━━ 🐍 helpers.py (10.1 kB)
┣━━ 🐍 log.py (546 Bytes)
┣━━ 🐍 monty_os.py (8.3 kB)
┣━━ 📄 py.typed (0 Bytes)
┗━━ 🐍 pydantic_type.py (4.3 kB)

Dependencies

Name Summary Marker
aiofile Asynchronous file operations.
fsspec File-system specification
pydantic Data validation using Python type hints
ripgrep-rs Fast regex search and .gitignore-aware file listing for Python, built on ripgrep's Rust crates
universal_pathlib pathlib api extended to use fsspec backends
adlfs Access Azure Blobs and Data Lake Storage (ADLS) Gen2 with fsspec and dask extra == "adlfs"
appwrite Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API extra == "appwrite"
beam-client (python_full_version < "3.14" or sys_platform != "win32") and extra == "beam"
httpx2 The next generation HTTP client. extra == "cloudflare"
codexed Async, typed Python client for the OpenAI Codex app-server JSON-RPC protocol extra == "codex"
e2b-code-interpreter E2B Code Interpreter - Stateful code execution extra == "e2b"
gcsfs Convenient Filesystem interface over GCS extra == "gcsfs"
python-gitlab The python wrapper for the GitLab REST and GraphQL APIs. extra == "gitlab"
hopx-ai Official Python SDK for HOPX.AI Sandboxes extra == "hopx"
yarl Yet another URL library extra == "httpx"
brotli Python bindings for the Brotli compression library extra == "httpx"
huggingface_hub Client library to download and publish models, datasets and other repos on the huggingface.co hub extra == "huggingface-hub"
jq jq is a lightweight and flexible JSON processor. extra == "jq"
PyYAML YAML parser and emitter for Python extra == "jsonschema"
requests Python HTTP for Humans. extra == "jsonschema"
fastmcp-slim The dependency-slim FastMCP package. extra == "mcp"
mcp Model Context Protocol SDK extra == "mcp"
microsandbox Python SDK for microsandbox — secure, fast microVM-based sandboxing. sys_platform != "win32" and extra == "microsandbox"
modal Python client library for Modal extra == "modal"
pydantic-monty Monty, the Python sandbox: bindings plus the worker binary extra == "monty"
notion-client Python client for the official Notion API extra == "notion-client"
openapi3 Client and Validator of OpenAPI 3 Specifications extra == "openapi3"
s3fs Convenient Filesystem interface over S3 extra == "s3fs"
SQLAlchemy Database Abstraction Library extra == "sqlite"
anyenv Compatibility layer for some basic operations to allow painless operation in PyOdide and Python pre-releases extra == "srt"
sshfs SSH Filesystem -- Async SSH/SFTP backend for fsspec extra == "ssh"
tree-sitter Python bindings to the Tree-sitter parsing library extra == "tree-sitter"
tree-sitter-python Python grammar for tree-sitter extra == "tree-sitter"
tree-sitter-c C grammar for tree-sitter extra == "tree-sitter"
tree-sitter-javascript JavaScript grammar for tree-sitter extra == "tree-sitter"
tree-sitter-typescript TypeScript and TSX grammars for tree-sitter extra == "tree-sitter"
tree-sitter-cpp C++ grammar for tree-sitter extra == "tree-sitter"
tree-sitter-rust Rust grammar for tree-sitter extra == "tree-sitter"
tree-sitter-go Go grammar for tree-sitter extra == "tree-sitter"
tree-sitter-json JSON grammar for tree-sitter extra == "tree-sitter"
tree-sitter-yaml YAML grammar for tree-sitter extra == "tree-sitter"
vercel-queue Vercel Queue client for Python extra == "vercel"
webdav4 WebDAV client library with an fsspec-based filesystem and a CLI extra == "webdav4"

License

MIT License - see LICENSE for details.

Basic Usage

AsyncUPath - Async File Operations

from upathtools import AsyncUPath
import asyncio

async def main():
    # Read a file asynchronously
    path = AsyncUPath("https://example.com/data.json")
    content = await path.aread_text()

    # Write asynchronously
    output = AsyncUPath("/tmp/output.txt")
    await output.awrite_text("Hello, async!")

    # Iterate directory
    async for item in AsyncUPath("/tmp").aiterdir():
        if await item.ais_file():
            print(item)

asyncio.run(main())

Batch File Operations

from upathtools import read_folder, list_files
import asyncio

async def main():
    # Read multiple files in parallel
    files = await read_folder(
        "src/",
        pattern="**/*.py",
        load_parallel=True
    )

    for filepath, content in files.items():
        print(f"{filepath}: {len(content)} bytes")

    # Just list files
    py_files = await list_files(
        "src/",
        pattern="**/*.py",
        recursive=True
    )

asyncio.run(main())

Common Patterns

Convert Paths

from upathtools.helpers import to_upath
from pathlib import Path

# Convert any path type to UPath
path = to_upath("/tmp/file.txt")
path = to_upath(Path("/tmp/file.txt"))

# Get async wrapper
async_path = to_upath("/tmp/file.txt", as_async=True)

Read Single File Async

from upathtools import read_path

async def main():
    # Text mode
    text = await read_path("file.txt", mode="rt")

    # Binary mode
    data = await read_path("image.png", mode="rb")

Write Files

from upathtools.helpers import write_file

# Handles parent directory creation automatically
write_file("content", "/deep/nested/path/file.txt")
write_file(b"binary", "/path/to/file.bin")

Copy Files

from upathtools.helpers import copy

# Copy between filesystems
copy("s3://bucket/source.txt", "/tmp/local.txt")

# Copy to directory (preserves name)
copy("/tmp/file.txt", "/backup/")

Find Files

from upathtools.helpers import multi_glob

# Find with multiple patterns
files = multi_glob(
    directory="src/",
    keep_globs=["**/*.py", "**/*.md"],
    drop_globs=["**/test_*.py", "**/__pycache__/**"]
)

Combine Multiple Files

from upathtools import read_folder_as_text

async def main():
    # Create single document from multiple files
    combined = await read_folder_as_text(
        "docs/",
        pattern="**/*.md",
        recursive=True
    )
    print(combined)

Cheat Sheet

Async Operations

Operation Code
Read text await path.aread_text()
Read bytes await path.aread_bytes()
Write text await path.awrite_text("data")
Write bytes await path.awrite_bytes(b"data")
Check exists await path.aexists()
Is file await path.ais_file()
Is dir await path.ais_dir()
Create dir await path.amkdir(parents=True)
Remove file await path.aunlink()
Iterate dir async for item in path.aiterdir()
Glob async for match in path.aglob("*.py")

Batch Operations

Operation Function
Read multiple files read_folder(path, pattern="**/*")
List files list_files(path, pattern="**/*")
Combine files read_folder_as_text(path, pattern="**/*")
Read single read_path(path, mode="rt")

Helpers

Operation Function
Convert to UPath to_upath(path)
Get filesystem upath_to_fs(path)
Copy file copy(src, dst)
Write file write_file(content, path)
Multi-glob multi_glob(keep_globs=[...])
Clean dir clean_directory(path)