Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

pathlib offers a set of classes to handle filesystem paths. It offers the following advantages over using string objects:

  • No more cumbersome use of os and os.path functions. Everything can be done easily through operators, attribute accesses, and method calls.

  • Embodies the semantics of different path types. For example, comparing Windows paths ignores casing.

  • Well-defined semantics, eliminating any warts or ambiguities (forward vs. backward slashes, etc.).

Requirements

Python 3.2 or later is required.

Install

easy_install pathlib or pip install pathlib should do the trick.

Examples

Importing the module classes:

>>> from pathlib import *

Listing Python source files in a directory:

>>> p = Path('.')
>>> [x for x in p if x.ext == '.py']
[PosixPath('test_pathlib.py'), PosixPath('setup.py'),
 PosixPath('pathlib.py')]

Listing subdirectories:

>>> [x for x in p if x.is_dir()]
[PosixPath('.hg'), PosixPath('docs'), PosixPath('dist'),
 PosixPath('__pycache__'), PosixPath('build')]

Navigating inside a directory tree:

>>> p = Path('/etc')
>>> q = p['init.d/reboot']
>>> q
PosixPath('/etc/init.d/reboot')
>>> q.resolve()
PosixPath('/etc/rc.d/init.d/halt')

Querying path properties:

>>> q.exists()
True
>>> q.is_dir()
False
>>> q.st_mode
33261

Opening a file:

>>> with q.open() as f: f.readline()
...
'#!/bin/bash\n'

Documentation

The full documentation can be read at Read the Docs.

Metadata

Release files for pathlib 0.3

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 0.3
File Size Uploaded Provenance
pathlib-0.3.tar.gz 27.8 kB Without provenance Details

Release files / pathlib-0.3.tar.gz

Download URL pathlib-0.3.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fbf7a43ab854391202845ce8f6c4acbfc3dd5fd1b4bc689f3b5433c8d9231c32
BLAKE2b-256 checksum
How to use checksums
946b2239738ba4f46b917cabdbd1d8bdc7c443a9498a6fa83dad388a785a872b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pathlib 0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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