pathlib-next
A robust, extensible pathlib-like base for any resource addressable as a
path. Same method names, signatures, semantics and exception types as
pathlib.Path wherever a pathlib.Path equivalent exists: write code once
against Path and it runs against your local disk, an in-memory tree, an FTP
server or the members of a zip or tar file, and against any path class built on
it. It has no dependencies. Deliberate differences from pathlib are listed in
Divergences from pathlib.
Features
| Class | Read | Write | List | Stat | mkdir | Delete | rename |
|---|---|---|---|---|---|---|---|
local path (LocalPath) |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
in-memory (MemPath) |
Yes | Yes | Yes | Yes | Yes | Yes | No (move() copies) |
FTP and FTPS (FTPPath) |
Yes | Yes | Yes (MLSD, NLST fallback) | Yes | Yes | Yes | Yes |
zip members (ZipPath) |
Yes | Local archive only | Yes | Yes | Local archive only | Local archive only | Local archive only |
tar members (TarPath, incl. gz/bz2/xz) |
Yes | No | Yes | Yes | No | No | No |
ArchivePath |
As ZipPath/TarPath for the format it detects |
Every class gets glob(), walk(), copy()/move(), rm() and PathSyncer
from the base classes; LocalPath and the other classes replace some of them
where the backend has a faster way.
- One path interface over local files, in-memory trees, FTP servers and
archive members, and over any class built on
Path. MemPath: a virtual filesystem for tests, mocks and transient data.FTPPath,ZipPath,TarPath,ArchivePath: an FTP server and the members of a zip or tar file as paths, on the standard library alone.pathlib_next.http:HTTPClientand a transport contract for HTTP requests on the standard library (redirects that never carryAuthorizationto another origin, TLS verified by default, aproxies=provider); therequestslibrary plugs in as a transport through thepathlib-next-requestsdistribution.PathSyncer: one-way, content-compared tree sync between any two implementations, with dry runs and event hooks.- Extensible: subclass
Pathfor any resource, and verify it with the bundled pytest contracts.
Paths for other places are separate distributions built on this one:
| Distribution | Provides |
|---|---|
uripath |
URIPath: one class for any URI, with the schemes file:, data:, ftp:, zip:, tar:, http: and dav:, and the uripath command |
sftppath |
SFTPPath (paramiko or asyncssh) |
objpath |
S3Path, GSPath and AZPath (Amazon S3, Google Cloud Storage, Azure Blob Storage) |
repopath |
RepoPath, GitHubPath and GitLabPath (the REST APIs of the hosting services) |
pathlib-next-requests |
RequestsTransport, the HTTP transport that sends through a requests.Session |
Installation
pip install pathlib-next
There are no extras and no dependencies: everything above runs on the standard
library. pytest is needed only to import pathlib_next.testing and
pathlib_next.http.testing.
Quick start
Local filesystem, as pathlib.Path:
from pathlib_next import Path
p = Path("data") / "report.txt"
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text("hello")
print(p.read_text())
In memory, 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}')
print([child.name for child in p.parent.iterdir()])
Archive members: the segments are the member path and the archive is any path:
import zipfile
from pathlib_next import ZipPath
with zipfile.ZipFile("backup.zip", "w") as archive:
archive.writestr("etc/config.ini", "[main]\n")
member = ZipPath("etc/config.ini", archive="backup.zip")
print(member.read_text())
print([child.name for child in member.parent.iterdir()])
FTP: nothing connects until the first operation:
from pathlib_next import FTPPath
for child in FTPPath("/pub", host="ftp.example.com", user="anonymous").iterdir():
print(child.name, child.stat().st_size)
Copy and sync across classes:
from pathlib_next import Path
from pathlib_next.mempath import MemPath
from pathlib_next.sync import PathSyncer
source = MemPath("/site")
(source / "css").mkdir(parents=True)
(source / "index.html").write_text("<h1>hi</h1>")
PathSyncer(remove_missing=True).sync(source, Path("site-copy"))
print(sorted(p.name for p in Path("site-copy").iterdir()))
API overview
| Module | Purpose |
|---|---|
pathlib_next.path |
Pathname/Path base classes and the derived operations |
pathlib_next.fspath |
LocalPath, PosixPathname, WindowsPathname |
pathlib_next.mempath |
MemPath in-memory filesystem |
pathlib_next.ftp |
FTPPath, FTPBackend (FTP and FTPS on ftplib) |
pathlib_next.archive |
ZipPath, TarPath, ArchivePath (members of a zip or tar file), make_archive, unpack_archive |
pathlib_next.http |
HTTPClient, HTTPTransport, HTTPResponse (HTTP requests on http.client) |
pathlib_next.protocols |
Stat, Chmod, BinaryOpen, NativeChecksum |
pathlib_next.sync |
PathSyncer, SyncEvent, PathAndStat |
pathlib_next.glob |
the glob engine behind Path.glob() |
pathlib_next.checksum |
md5, sha256, stream, native |
pathlib_next.providers |
the helpers a class built on Path calls |
pathlib_next.exceptions |
PathError, NonRelativePatternError |
pathlib_next.testing |
pytest contracts for custom implementations |
pathlib_next.http.testing |
testing support (not stable API): the pytest suite that holds an HTTP transport to the promises of the built-in one |
The full reference is on the documentation site;
an agent-oriented API summary ships inside the package as
pathlib_next/AGENTS.md.
Extending
Subclass Path for a resource of your own (MemPath is the reference), as
worked through in
Extending.
pathlib_next.testing provides the pytest contracts (PurePathContract,
ReadPathContract, PathContract) and populate_fixture_tree() that every
class of the package and of the distributions above is verified with.
Supported Python versions
Python 3.9 through 3.14. CI runs the full suite on Ubuntu for every version
from 3.9 to 3.14, on Windows and macOS for 3.9 and 3.14, and with nothing but
pytest and pyftpdlib installed on 3.9 and 3.14.
Development
pip install -e ".[dev]"
python -m pytest -q -rs
Tests that need an optional package are skipped when it is missing, so check
the skip list (-rs). Contributor notes (virtual environments, formatting, CI,
releases) are in the repository's
AGENTS.md;
benchmarks are described in
Benchmarks. To preview
the documentation: pip install -e ".[docs]" then mkdocs serve.
Changes are recorded in the changelog.
Releasing
- Move the
[Unreleased]entries ofCHANGELOG.mdunder a new## [x.y.z] - <date>heading and add its link definition at the bottom. - Bump
versioninpyproject.tomlin the same commit. - Before 1.0 the minor version changes only when the documented API breaks; new methods, new optional arguments and fixes are patch releases.
- Run the full suite on the oldest and the newest supported Python,
mkdocs build --strictandpython -m build. - Push
main, then thev*tag: the release workflow tests, builds and publishes to PyPI and creates the GitHub release.
License
MIT; see LICENSE.
Metadata
Release files for pathlib-next 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pathlib_next-0.10.0.tar.gz | 581.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pathlib_next-0.10.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 861.4 kB
Release files / pathlib_next-0.10.0.tar.gz
| Download URL | pathlib_next-0.10.0.tar.gz |
|---|---|
| Size | 581.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eac5f4c872b31c106a39a043a99c86f2c89e0f974239c2497b3498dfaa515b1c
|
|
BLAKE2b-256 checksum How to use checksums |
11aad7477577796a30aed669405723a82c7cb7005eb96d5965c12edf87ffb471
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pathlib_next-0.10.0-py3-none-any.whl
| Download URL | pathlib_next-0.10.0-py3-none-any.whl |
|---|---|
| Size | 280.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f110fec239030e0cb24e0a288e13199fabeef421fa2f47828252f95798aa3e2
|
|
BLAKE2b-256 checksum How to use checksums |
bb3d67a0171481fb83ba01ffa67d47df2b72f35a1ad0f8dc113badeb236b2b23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency log