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. 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: HTTPClient and a transport contract for HTTP requests on the standard library (redirects that never carry Authorization to another origin, TLS verified by default, a proxies= provider); the requests library plugs in as a transport through the pathlib-next-requests distribution.
  • PathSyncer: one-way, content-compared tree sync between any two implementations, with dry runs and event hooks.
  • Extensible: subclass Path for 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

  1. Move the [Unreleased] entries of CHANGELOG.md under a new ## [x.y.z] - <date> heading and add its link definition at the bottom.
  2. Bump version in pyproject.toml in the same commit.
  3. Before 1.0 the minor version changes only when the documented API breaks; new methods, new optional arguments and fixes are patch releases.
  4. Run the full suite on the oldest and the newest supported Python, mkdocs build --strict and python -m build.
  5. Push main, then the v* 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)

Source distribution for pathlib-next 0.10.0
File Size Uploaded
pathlib_next-0.10.0.tar.gz 581.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pathlib-next 0.10.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

0.10.1

2 release files

This release

0.10.0 This release

2 release files

0.9.14

2 release files

0.9.11

2 release files

0.9.10

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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