URI & Schemes API
pathlib_next.uri
Uri(*uris, **options)
Bases: Pathname
A pure (no I/O) RFC 3986 URI, lazily parsed into source (scheme/
userinfo/host/port), path, query, and fragment on first access.
Join semantics (multiple constructor args, or /) are pathlib-
joinpath-like, not RFC 3986 reference resolution -- see
_load_parts's docstring and docs/divergences.md.
Source code in src/pathlib_next/uri/__init__.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
normalized_path
property
Return the normalized path using posixpath rules.
parent
property
The logical parent of the path.
parts
property
The tuple of URI components: (source, path, query, fragment).
__str__()
Return the string representation of the path. Deliberately
sanitized (password dropped from userinfo) since str() is what
logging/printing reach for -- this does NOT round-trip a
credentialed URI. Use as_uri(sanitize=False) for the full URI
including credentials.
Source code in src/pathlib_next/uri/__init__.py
260 261 262 263 264 265 266 | |
host_fspath()
Return .path for any scheme whose path component is a
filesystem path on the URI's own host (see _host_filesystem_path),
for building a command line that runs on that host (e.g. via a
remote executor). Unlike __fspath__, this never falls back to
treating the path as local -- it raises NotImplementedError for
schemes with no host-filesystem meaning (http:, s3:, ...).
Source code in src/pathlib_next/uri/__init__.py
282 283 284 285 286 287 288 289 290 291 | |
is_absolute()
True if the path is absolute.
Source code in src/pathlib_next/uri/__init__.py
429 430 431 | |
is_local()
Return True if the URI points to a local resource.
Source code in src/pathlib_next/uri/__init__.py
475 476 477 | |
is_relative_to(other)
Return True if the path is relative to another path or False.
Source code in src/pathlib_next/uri/__init__.py
433 434 435 436 437 438 439 440 441 442 443 444 445 | |
with_fragment(fragment)
Return a new URI with the fragment replaced.
Source code in src/pathlib_next/uri/__init__.py
379 380 381 | |
with_path(path)
Return a new URI with the path replaced.
Source code in src/pathlib_next/uri/__init__.py
364 365 366 367 368 369 370 371 | |
with_query(query)
Return a new URI with the query replaced.
Source code in src/pathlib_next/uri/__init__.py
373 374 375 376 377 | |
with_segments(*segments)
Return a new URI with the path segments replaced.
Source code in src/pathlib_next/uri/__init__.py
358 359 360 361 362 | |
with_source(source)
Return a new URI with the source replaced.
Source code in src/pathlib_next/uri/__init__.py
354 355 356 | |
UriPath(*uris, **options)
Uri + Path (I/O) + scheme dispatch. UriPath(...) constructs
the concrete subclass registered for the URI's scheme (via __SCHEMES)
-- e.g. UriPath("http://...") returns an HttpPath. Subclass this
and set __SCHEMES to add a new scheme (Track B of extending this
library; see docs/guides/extending.md); implement the I/O surface
(_listdir or _scandir, stat, _open, ...) documented in
docs/guides/extending.md. Prefer overriding _scandir() over _listdir() when the
listing call already returns type/size/mtime metadata (PROPFIND, MLSD,
listdir_attr, an S3 list page, ...) -- walk()/glob() then answer
is_dir() on the results for free, without a stat request per entry.
Source code in src/pathlib_next/uri/__init__.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
backend
property
The connection or session state backend instance.
with_backend(backend)
Return a new path instance sharing the same backend state.
Source code in src/pathlib_next/uri/__init__.py
664 665 666 | |
pathlib_next.uri.source
Source
Bases: NamedTuple
A URI's scheme/userinfo/host/port -- everything before the path.
Falsy (bool(source) is False) when every field is empty/None.
__str__()
Deliberately sanitized (password dropped from userinfo), same
rationale as Uri.__str__: this is what logging/printing reach
for, and a Source on a failing call stack must not leak a
credential. Does NOT round-trip a credentialed source -- use
as_str(sanitize=False) for the unredacted form.
Source code in src/pathlib_next/uri/source.py
230 231 232 233 234 235 236 237 | |
as_str(sanitize=True)
Compose this Source back into an authority string
(scheme://userinfo@host:port). sanitize=True (the default,
matching __str__) drops the password from userinfo; pass
sanitize=False for the full, credentialed round trip -- the
same escape hatch Uri.as_uri(sanitize=False) provides one layer
up. Mirrors Uri.as_uri()'s name/kwarg exactly so both classes
are used the same way.
Source code in src/pathlib_next/uri/source.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
is_local()
cached
Whether host resolves to this machine.
Caches per unique Source (Source is an immutable value type), since this does a DNS/hosts-file lookup -- never call it on a hot path uncached.
The hostname->address step uses netimps.resolve() (default
backend chain: dnspython, then the OS resolver via
getaddrinfo() -- hosts file, NSS, DNS, OS cache -- then
nslookup as a last resort), trying both "a"/"aaaa" record
types and treating host as local if ANY resolved address is.
netimps.resolve() gained OS-resolver-chain support in 0.2.0 --
before that it was dnspython-only, which is why this method
originally kept socket.gethostbyname() for this step (see
.agents/findings/processed/2026-07-29_netimps_adoption_survey.md
and the companion finding filed against netimps itself). The
"is this address MINE" comparison uses netimps.is_local_address(),
which enumerates real network interfaces
(netimps.get_interfaces()) instead of the weaker
socket.getaddrinfo(socket.gethostname(), None) this project used
originally -- that approach missed addresses not tied to the
resolvable hostname (VMs, containers, VPN interfaces, additional
NICs on a multi-homed host).
host as a bare IP-literal str (e.g. a directly-constructed
Source(..., host="::1", ...), bypassing _decode_host()'s usual
bracket-literal parsing) is handled by netimps.try_parse()
without going through resolution at all.
Source code in src/pathlib_next/uri/source.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
pathlib_next.uri.query
Query
Bases: str
A URI query string (str subclass) that can also be built from a
dict/list of pairs and decoded back with to_dict()/iteration.