• Stars
    star
    1,103
  • Rank 42,076 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created over 12 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Object-oriented file system path manipulation

tests Ruff Code style: Black https://readthedocs.org/projects/path/badge/?version=latest https://img.shields.io/badge/skeleton-2023-informational https://tidelift.com/badges/package/pypi/path

path (aka path pie, formerly path.py) implements path objects as first-class entities, allowing common operations on files to be invoked on those path objects directly. For example:

from path import Path

d = Path("/home/guido/bin")
for f in d.files("*.py"):
    f.chmod(0o755)

# Globbing
for f in d.files("*.py"):
    f.chmod("u+rwx")

# Changing the working directory:
with Path("somewhere"):
    # cwd in now `somewhere`
    ...

# Concatenate paths with /
foo_txt = Path("bar") / "foo.txt"

Path pie is hosted at Github.

Find the documentation here.

Guides and Testimonials

Yasoob wrote the Python 101 Writing a Cleanup Script based on path.

Advantages

Python 3.4 introduced pathlib, which shares many characteristics with path. In particular, it provides an object encapsulation for representing filesystem paths. One may have imagined pathlib would supersede path.

But the implementation and the usage quickly diverge, and path has several advantages over pathlib:

  • path implements Path objects as a subclass of str, and as a result these Path objects may be passed directly to other APIs that expect simple text representations of paths, whereas with pathlib, one must first cast values to strings before passing them to APIs unaware of pathlib. This shortcoming was somewhat mitigated by PEP 519, in Python 3.6.
  • path give quality of life features beyond exposing basic functionality of a path. path provides methods like rmtree (from shlib) and remove_p (remove a file if it exists), properties like .permissions, and sophisticated walk, TempDir, and chmod behaviors.
  • As a PyPI-hosted package, path is free to iterate faster than a stdlib package. Contributions are welcome and encouraged.
  • path provides a uniform abstraction over its Path object, freeing the implementer to subclass it readily. One cannot subclass a pathlib.Path to add functionality, but must subclass Path, PosixPath, and WindowsPath, even if one only wishes to add a __dict__ to the subclass instances. path instead allows the Path.module object to be overridden by subclasses, defaulting to the os.path. Even advanced uses of path.Path that subclass the model do not need to be concerned with OS-specific nuances.

This path project has the explicit aim to provide compatibility with pathlib objects where possible, such that a path.Path object is a drop-in replacement for pathlib.Path* objects. This project welcomes contributions to improve that compatibility where it's lacking.

Origins

The path.py project was initially released in 2003 by Jason Orendorff and has been continuously developed and supported by several maintainers over the years.

For Enterprise

Available as part of the Tidelift Subscription.

This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

Learn more.

More Repositories

1

keyring

Python
1,248
star
2

inflect

Correctly generate plurals, ordinals, indefinite articles; convert numbers to words
Python
962
star
3

irc

Full-featured Python IRC library for Python.
Python
377
star
4

wolframalpha

Python
138
star
5

pip-run

pip-run - dynamic dependency loader for Python
Python
105
star
6

skeleton

A generic project skeleton for Python projects.
97
star
7

cssutils

Python
59
star
8

configparser

backport of configparser from Python 3
Python
47
star
9

zipp

Python
38
star
10

backports.functools_lru_cache

Python
37
star
11

svg.charts

SVG Charting Library for Python
Python
25
star
12

jaraco.windows

Python
24
star
13

cmdix

Fork of https://launchpad.net/pycoreutils
Python
22
star
14

keyrings.alt

Python
21
star
15

tempora

Python
19
star
16

jaraco.functools

Python
16
star
17

jaraco.text

Python
15
star
18

jaraco.clipboard

Python
14
star
19

jaraco.video

Python
13
star
20

jaraco.collections

Python
11
star
21

oathtool

Python
10
star
22

jaraco.nxt

Python
7
star
23

portend

Python
6
star
24

jaraco.itertools

Python
6
star
25

jaraco.abode

Python
6
star
26

jaraco.classes

Python
6
star
27

jaraco.mongodb

MongoDB Utilities including an oplog replay tool
Python
5
star
28

jaraco.docker

Python
5
star
29

xlsxcessive

Python
4
star
30

jaraco.crypto

Python
4
star
31

jaraco.packaging

Python
4
star
32

jaraco.context

Python
3
star
33

pywin32-ctypes

A limited subset of pywin32 re-implemented using ctypes
Python
3
star
34

pyevent

Automatically exported from code.google.com/p/pyevent
C
3
star
35

rst.linker

Python
3
star
36

jaraco.keyring

Python
3
star
37

jaraco.compat

2
star
38

freedompop

Python
2
star
39

jaraco.envs

Python
2
star
40

jaraco.media

Python
2
star
41

setuptools_svn

Python
2
star
42

backports.unittest_mock

Python
2
star
43

recapturedocs

Source for the Recapturedocs service
Python
2
star
44

backports.entry_points_selectable

Python
1
star
45

pytest-enabler

Python
1
star
46

jaraco.path

Python
1
star
47

jaraco.fabric

Python
1
star
48

keyrings.firefox

Python
1
star
49

jaraco.apt

Python
1
star
50

nspektr

Python
1
star
51

jaraco.vcs

Python
1
star
52

dropbox-index

Fork of http://code.google.com/p/kosciak-misc/wiki/DropboxIndex
Python
1
star
53

jaraco.develop

Python
1
star
54

jaraco.tidelift

HTML
1
star
55

transformers

Jupyter Notebook
1
star
56

http-okapi

HTML
1
star
57

multipy-tox

Dockerfile
1
star
58

jaraco.modb

Jupyter Notebook
1
star
59

jaraco.pmxbot

Python
1
star
60

pytest-perf

Python
1
star
61

jaraco.util

Python
1
star
62

singledispatch

Python
1
star
63

jaraco.services

Python
1
star
64

pipx-1539

1
star