Skip to main content

pathlib_next

Version Python versions License: MIT Docs CI

A robust, extensible pathlib-like base for any resource addressable as a path or URI. Same method names, signatures, semantics, and exception types as pathlib.Path wherever a pathlib.Path equivalent exists -- write code once against Path/UriPath and it works against your local disk, an in-memory tree, an HTTP index, or an SFTP server. Every intentional divergence from pathlib's behavior is documented, not silent -- see docs/divergences.md.

Features

Scheme Read Write List Stat mkdir Delete rename Extra required
LocalPath / file: Yes Yes Yes Yes Yes Yes Yes none
mem: (MemPath) Yes Yes Yes Yes Yes Yes No none
data: (RFC 2397) Yes No No Yes No No No none
zip: / tar: (archive !/ paths) Yes zip: new entries, local archive Yes Yes zip: local No No none
ftp(s): Yes Yes Yes Yes Yes Yes Yes none
http(s): Yes No Yes (HTML index) Yes No No No http
dav(s): (WebDAV) Yes Yes Yes (PROPFIND) Yes Yes Yes Yes http
sftp: Yes Yes Yes Yes Yes Yes Yes sftp
s3: Yes Yes Yes (prefix emulation) Yes Yes Yes Yes (same bucket) s3

Every scheme shares the same glob(), walk(), copy()/move(), rm() implementations -- see the full matrix and notes in Schemes.

  • Unified path interface across local files, in-memory paths, archive members, and file/data/ftp/http/dav/sftp/s3 URIs.
  • MemPath -- a lightweight virtual filesystem for mocks, tests, or transient storage.
  • PathSyncer -- one-way checksum-driven tree sync between any two Path implementations, with dry-run and event hooks.
  • Query/Source -- parse and serialize URL query strings and URI authority components.
  • Extensible two ways: subclass Path directly for a custom non-URI resource, or subclass UriPath for a new URI scheme -- see Extending.

Installation

pip install pathlib_next

Optional features/extras:

Extra/flag Adds Needed for
uri uritools URI parsing (any UriPath scheme)
http requests http(s): and dav(s): (WebDAV) paths
sftp paramiko sftp: path operations and transfers (sync backend)
sftp-async asyncssh sftp: path operations via the asyncssh backend instead (see guides/schemes.md's sftp: row for selection precedence)
s3 boto3 s3://bucket/key paths

import pathlib_next and LocalPath/MemPath work with no extras installed; data:, ftp(s):, and zip:/tar: only need the uri extra (they're stdlib-based otherwise).

Quick start

Local filesystem -- drop-in pathlib.Path:

from pathlib_next import Path

p = Path("./data") / "report.txt"
p.write_text("hello")
print(p.read_text())

In-memory (mem:) -- a virtual filesystem, no disk I/O:

from pathlib_next.mempath import MemPath

p = MemPath("/config/settings.json")
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text('{"debug": true}')

file: -- the same local filesystem, addressed as a URI:

from pathlib_next.uri import UriPath

p = UriPath("file:./data/report.txt")
print(p.read_text())

http(s): -- read files and list Apache/nginx-style directory indexes:

from pathlib_next.uri import UriPath

p = UriPath("http://example.com/data/")
for child in p.iterdir():
    if child.is_file():
        print(child.name, child.stat().st_size)

sftp: -- same interface, over SSH:

from pathlib_next.uri import UriPath

p = UriPath("sftp://user@host/var/log/app.log")
print(p.read_text())

zip:/tar: -- address a member inside an archive (Java-style !/ separator; the archive half is itself any URI -- file:, http:, sftp:, ...):

from pathlib_next.uri import UriPath

member = UriPath("zip:file:./backup.zip!/etc/config.ini")
print(member.read_text())

Also built in: data: (RFC 2397 inline payloads), ftp(s): (stdlib ftplib), dav(s): (WebDAV, full read/write over HTTP), and s3: (boto3) -- one example per scheme in Schemes.

Extending

Two first-class ways to add a new path-addressable resource -- both covered in depth, with worked examples, in Extending:

  • Subclass Path directly for a custom, non-URI resource (MemPath is the reference exemplar).
  • Subclass UriPath and set __SCHEMES for a new URI scheme (FileUri/ HttpPath/SftpPath are the built-in examples).

pathlib_next.testing provides reusable pytest mixins (PurePathContract, ReadPathContract, and PathContract) covering the baseline contracts for various levels of capabilities -- subclass one of them with a root fixture to verify your own implementation.

API overview

Module/Package Purpose
pathlib_next.path Base Path implementation and protocols
pathlib_next.uri URI/URL specific path support and Query utils
pathlib_next.uri.schemes Built-in schemes: file, data, ftp, zip/tar, http, dav, sftp, s3
pathlib_next.mempath In-memory transient path structure
pathlib_next.utils.sync Synchronization functions and PathSyncer class
pathlib_next.testing PathContract, a pytest mixin for verifying custom implementations

Supported Python versions

Python >= 3.9, tested on 3.9 and 3.13 in CI (see .github/workflows/test.yml).

Development

pip install -e ".[dev,uri,http,sftp,sftp-async]"
pytest -q

If you maintain separate virtual environments per Python version locally (e.g. .venv/3.9/, .venv/3.13/), run the same pytest -q in each -- CI does the equivalent across Python 3.9/3.13 on Linux, macOS, and Windows.

Benchmarks

Run the benchmark suite using:

python benchmarks/bench.py

A benchmark report and methodology notes live in docs/benchmarks.md.

Releasing

This project follows Semantic Versioning and keeps a CHANGELOG.md. Pushing a tag matching v* triggers the release workflow: test gate → build → publish → docs deploy.

Documentation site

MkDocs builds the API reference from docs/, published on every release. To preview locally: mkdocs serve.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathlib_next-0.8.5.tar.gz (188.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathlib_next-0.8.5-py3-none-any.whl (113.5 kB view details)

Uploaded Python 3

File details

Details for the file pathlib_next-0.8.5.tar.gz.

File metadata

  • Download URL: pathlib_next-0.8.5.tar.gz
  • Upload date:
  • Size: 188.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pathlib_next-0.8.5.tar.gz
Algorithm Hash digest
SHA256 ef50ff2a6fd6661094a2be316657e97b43c7e8ec34f01d9f1662e0735d2495fe
MD5 02a54551356120169f07d1a5e443678e
BLAKE2b-256 bc29db45b67c6c65cdd5ab8ff56287508847901b9b2802f05803230bc4b1f262

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathlib_next-0.8.5.tar.gz:

Publisher: release.yml on jose-pr/pathlib_next

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pathlib_next-0.8.5-py3-none-any.whl.

File metadata

  • Download URL: pathlib_next-0.8.5-py3-none-any.whl
  • Upload date:
  • Size: 113.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pathlib_next-0.8.5-py3-none-any.whl
Algorithm Hash digest
SHA256 33726ec5630e5976df7c1bae06d976113b91dd311584f164567d30988471326c
MD5 fec3d03f2cd51023d758fb5db6a5dd9e
BLAKE2b-256 c292e85d764c51ee669842b65db104f19c8f142663ca47e20ea4d95e79d64562

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathlib_next-0.8.5-py3-none-any.whl:

Publisher: release.yml on jose-pr/pathlib_next

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.6

2 files

This release

0.8.5 This release

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.5

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page