Skip to main content

An extended and more powerful pathlib.

Project description

Documentation Status https://github.com/MacHu-GWU/pathlib_mate-project/workflows/CI/badge.svg https://codecov.io/gh/MacHu-GWU/pathlib_mate-project/branch/master/graph/badge.svg https://img.shields.io/pypi/v/pathlib_mate.svg https://img.shields.io/pypi/l/pathlib_mate.svg https://img.shields.io/pypi/pyversions/pathlib_mate.svg https://img.shields.io/pypi/dm/pathlib_mate.svg https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social
https://img.shields.io/badge/Link-Document-blue.svg https://img.shields.io/badge/Link-API-blue.svg https://img.shields.io/badge/Link-Source_Code-blue.svg https://img.shields.io/badge/Link-Install-blue.svg https://img.shields.io/badge/Link-GitHub-blue.svg https://img.shields.io/badge/Link-Submit_Issue-blue.svg https://img.shields.io/badge/Link-Request_Feature-blue.svg https://img.shields.io/badge/Link-Download-blue.svg

Welcome to pathlib_mate Documentation

pathlib is an awesome library handling path in different OS. And it’s been added into standard library since Python3.4. pathlib_mate gives extensive methods and attributes, makes pathlib more powerful and user-friendly.

Features:

Convenient Attribute Accessor:

>>> p = Path("/Users/username/test.py").

>>> p.abspath
/Users/username/test.py

>>> p.basename
test.py

>>> p.fname
test

>>> p.ext
.py

>>> p.dirname
username

>>> p.dirpath
/Users/username

>>> p.size
1500

>>> p.size_in_text
1.46 KB

>>> p.create_datetime
datetime(2018, 1, 15, 8, 30, 15)

>>> p.md5
415f12f07a7e01486cc82856621e05bf

>>> p.sha256
d51512cb0ac71484c01c475409a73225d0149165024d7aac6d8e655eedf2c025

>>> p.sha512
7882fc375840cafa364eaf29dc424645b72fcdbe61fc3326c5afd98e70f696e4f390e0e3f159eac2cb60cedc0992ef7b5f8744a4481911e914a7c5b979e6de68

Powerful Path Search:

>>> p = Path("/Users/username/Documents")

>>> for path in p.select_file(recursive=True)
...

>>> for path in p.select_file(recursive=False)
...

>>> for path in p.select_dir(recursive=True)
...

>>> for image_file in p.select_by_ext([".jpg", ".png"])
...

>>> for big_file in p.select_by_size(min_size=1000000)
...

>>> for video_file in p.select_video():
...

# You can customize the filter anyway you want
>>> def py_filter(p): return ".py" == p.ext.lower()
>>> for py_file in p.select_file(py_filter):
...

Eazy to use File / Dir Operation:

>>> p = Path("/Users/username/Documents/Readme.txt")

# mutate
>>> p.change(new_ext=".md")
/Users/username/Documents/Readme.md

>>> p.change(new_fname="Tutorial")
/Users/username/Documents/Tutorial.txt

>>> p.change(new_basename="README.rst")
/Users/username/Documents/README.rst

>>> p.change(new_dirname="Downloads")
/Users/username/Downloads/Readme.txt

>>> p.change(new_dirpath="/User/username/Downloads)
/Users/username/Downloads/Readme.txt

>>> p.change(new_abspath="/Users/username/Downloads/Readme.txt")
/Users/username/Downloads/Readme.txt

# copy
>>> p.moveto(new_ext=".md", makedirs=True)

# cut
>>> p.copyto(new_ext=".md", makedirs=True)

# delete
>>> p.remove()

# delete file or directory recursively, ignore if not exists
>>> p.remove_if_exists()

# make dir and required parents recursively, if not exists
>>> p.mkdir_if_not_exists()

Atomic Write Support:

If anything wrong happens during writing big chunk of data into a file. It may leave you an incomplete file. Atomic write can guarantee either 100% done or nothing happens.

Thanks for atomicwrites project. Now pathlib_mate supports atomic write API:

>>> p = Path("test.dat")
>>> s = "Hello World"
>>> b = s.encode("utf-8)
>>> p.atomic_write_bytes(b, overwrite=True)
>>> p.atomic_write_text(s, overwrite=True)

Powerful Production Tools:

>>> p = Path("/Users/username/Documents/Github/pathlib_mate-project")

>>> p.print_big_dir_and_big_file()
...

>>> p.file_stat()
{"file": 122, "dir": 41, "size": 619682}

# file statistics, include sub folder
>>> p.file_stat_for_all()

# make an zip archive for the directory, auto naming
>>> p.make_zip_archive()

# make an zip archive for the directory, auto naming
>>> p.backup()

Install

pathlib_mate is released on PyPI, so all you need is:

$ pip install pathlib_mate

To upgrade to latest version:

$ pip install --upgrade pathlib_mate

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

pathlib_mate-1.1.1.tar.gz (107.5 kB view details)

Uploaded Source

Built Distribution

pathlib_mate-1.1.1-py2.py3-none-any.whl (121.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pathlib_mate-1.1.1.tar.gz.

File metadata

  • Download URL: pathlib_mate-1.1.1.tar.gz
  • Upload date:
  • Size: 107.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.11

File hashes

Hashes for pathlib_mate-1.1.1.tar.gz
Algorithm Hash digest
SHA256 dac2290c21d957768b2bf4a3f101ece268019f20522215ce15ced52d828dacb8
MD5 98d16f1c50f80611fea8af89218ba051
BLAKE2b-256 32614c601c2a17356b870c212423c19401281a155089344112842249e1832b4f

See more details on using hashes here.

File details

Details for the file pathlib_mate-1.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pathlib_mate-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 011cad4d623ced7c95ca05644d4678f336c1866860b73d4030782e4ff6026019
MD5 66a872f2297484766dd0a7616b3d845a
BLAKE2b-256 7b7985cc1b005d8f70a4d0f30a5c7bda586239f4382303b6e4583b221a8e8d54

See more details on using hashes here.

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