Skip to main content

pathlib

Standard library Module View source

Native filesystem paths represented by the immutable Path tuple class.

Lexical operations preserve .. components. Methods that change the filesystem do not change the stored path.

class Path
@tuple
class Path
Constructors 1
__new__
__new__(*segments) -> Path
Properties 10
drive
@property
drive(self: Self) -> str
root
@property
root(self: Self) -> str
anchor
@property
anchor(self: Self) -> str
parts
@property
parts(self: Self) -> DynamicTuple[str]
name
@property
name(self: Self) -> str
suffix
@property
suffix(self: Self) -> str
suffixes
@property
suffixes(self: Self) -> List[str]
stem
@property
stem(self: Self) -> str
parent
@property
parent(self: Self)
parents
@property
parents(self: Self) -> DynamicTuple[Path]
Methods 48
joinpath
joinpath(self: Self, *segments)
as_posix
as_posix(self: Self) -> str
with_name
with_name(self: Self, name: str)
with_stem
with_stem(self: Self, stem: str)
with_suffix
with_suffix(self: Self, suffix: str)
is_absolute
is_absolute(self: Self) -> bool
is_relative_to
is_relative_to(self: Self, other) -> bool
relative_to
relative_to(self: Self, other, *, walk_up: bool = False)
cwd
cwd()
home
home()
absolute
absolute(self: Self)
resolve
resolve(self: Self, strict: bool = False)
expanduser
expanduser(self: Self)
as_uri
as_uri(self: Self) -> str
stat
stat(self: Self, *, follow_symlinks: bool = True)
lstat
lstat(self: Self)
exists
exists(self: Self, *, follow_symlinks: bool = True) -> bool
is_file
is_file(self: Self, *, follow_symlinks: bool = True) -> bool
is_dir
is_dir(self: Self, *, follow_symlinks: bool = True) -> bool
is_socket
is_socket(self: Self) -> bool
is_fifo
is_fifo(self: Self) -> bool
is_block_device
is_block_device(self: Self) -> bool
is_char_device
is_char_device(self: Self) -> bool
is_mount
is_mount(self: Self) -> bool
samefile
samefile(self: Self, other) -> bool
open
open(self: Self, mode: str = "r", encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None)
open[mode: Literal[str]](self: Self, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None)
read_text
read_text(self: Self, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> str
read_bytes
read_bytes(self: Self) -> bytes
write_text
write_text(self: Self, data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int
write_bytes
write_bytes(self: Self, data: bytes) -> int
iterdir
iterdir(self: Self)
mkdir
mkdir(self: Self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False)
rmdir
rmdir(self: Self)
rename
rename(self: Self, target)
replace
replace(self: Self, target)
chmod
chmod(self: Self, mode: int, *, follow_symlinks: bool = True)
lchmod
lchmod(self: Self, mode: int)
touch
touch(self: Self, mode: int = 0o666, exist_ok: bool = True)
match
match(self: Self, pattern, *, case_sensitive: Optional[bool] = None) -> bool
full_match
full_match(self: Self, pattern, *, case_sensitive: Optional[bool] = None) -> bool
glob
glob(self: Self, pattern, *, case_sensitive: Optional[bool] = None, recurse_symlinks: bool = False)
rglob
rglob(self: Self, pattern, *, case_sensitive: Optional[bool] = None, recurse_symlinks: bool = False)
walk
walk(self: Self, top_down: bool = True, on_error = None, follow_symlinks: bool = False)
Special methods 12
__str__
__str__(self: Self) -> str
__repr__
__repr__(self: Self) -> str
__fspath__
__fspath__(self: Self) -> str
__hash__
__hash__(self: Self) -> int
__eq__
__eq__(self: Self, other) -> bool
__ne__
__ne__(self: Self, other, /) -> bool
__lt__
__lt__(self: Self, other: Path) -> bool
__le__
__le__(self: Self, other: Path) -> bool
__gt__
__gt__(self: Self, other: Path) -> bool
__ge__
__ge__(self: Self, other: Path) -> bool
__truediv__
__truediv__(self: Self, other)
__rtruediv__
__rtruediv__(self: Self, other)