Skip to main content

Extends the standard library pathlib.Path class.

Project description

pathier

Extends the standard library pathlib.Path class.

Installation

Install with:

pip install pathier

Usage

Functions the same as pathlib.Path, but with added functions and some altered default arguments.

Navigation

New paths can be obtained by:

  • naming the parent with moveup()
  • subtracting a number of levels from the current path
  • naming the parent of the path you actually want with move_under()
  • separating a relative path at a named parent with separate()
>>> from pathier import Pathier
>>> path = Pathier("C:/some/directory/to/some/file/on/the/system")
>>> path.moveup("directory")
WindowsPath('C:/some/directory')
>>> path - 3
WindowsPath('C:/some/directory/to/some/file')
>>> path.move_under("directory")
WindowsPath('C:/some/directory/to')
>>> path.separate("file")
WindowsPath('on/the/system')
>>> path.separate("file", True)
WindowsPath('file/on/the/system')

Manipulation

Can dump and load toml and json files without needed to explicityly import and call functions from the respective libraries:

from pathier import Pathier
path = Pathier("some_file.toml")
content = path.loads()
path.with_suffix(".json").dumps(content, indent=2)

Pathier().mkdir() creates parent directories and doesn't throw an error if the path already exists by default.

Pathier().write_text() and Pathier().write_bytes() will create parent directories by default if they won't exist.

Pathier().write_text() will also try to cast the data to be written to a string if a TypeError is thrown.

Pathier().delete() will delete a file or directory, event if that directory isn't empty.

Pathier().copy() will copy a file or a directory tree to a new destination and return a Pathier object for the new path
By default, files in the destination will not be overwritten.

Stats and Comparisons

>>> from pathier import Pathier
>>> p = Pathier.cwd() / "pathier.py"
>>> i = p.parent / "__init__.py"
>>> p.dob
datetime.datetime(2023, 3, 31, 18, 43, 12, 360000)
>>> p.age
8846.024934
>>> p.mod_date
datetime.datetime(2023, 3, 31, 21, 7, 30)
>>> p.mod_delta
207.488857
>>> p.size()
10744
>>> p.size(True)
'10.74 kb'
>>> p.is_larger(i)
True
>>> p.is_older(i)
False
>>> p.modified_more_recently(i)
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathier-0.5.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

pathier-0.5.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pathier-0.5.0.tar.gz.

File metadata

  • Download URL: pathier-0.5.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for pathier-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1781a910f65de0f0d5d211984641221030c330448ef93a28947d278498310613
MD5 1b8724e77a7a654daeda236fe765a25c
BLAKE2b-256 2003fb4c6ae2ad3f988e3f6faea22daa6e2d44a5c26a0faa0dd841bfb23a3718

See more details on using hashes here.

Provenance

File details

Details for the file pathier-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pathier-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for pathier-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99774f244c5d70e615b3eab875363508613196a4746c907777d0c7fc2a3c78e1
MD5 df70bff83fd728e2b29661e5d6e01c30
BLAKE2b-256 a13711ba323860304c64a338197e21f3994c87822a78f280a80994c7fc0701a1

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page