Skip to main content

No project description provided

Project description

pathlibutil

PyPI - Python Version PyPI PyPI - Downloads PyPI - License GitHub Workflow Test)


pathlibutil.Path inherits from pathlib.Path with some useful built-in python functions.

  • Path().hexdigest() to calculate and Path().verify() for verification of hexdigest from a file
  • Path.default_hash to configurate default hash algorithm for Path class (default: 'md5')
  • Path().size() to get size in bytes of a file or directory
  • Path().read_lines() to yield over all lines from a file until EOF
  • contextmanager to change current working directory with with statement

Installation

pip install pathlibutil

Usage

from pathlibutil import Path

readme = Path('README.md')

print(f'File size: {readme.size()} Bytes')
print(f'File sha1: {readme.hexdigest("sha1")}')

print('-- File content --')
for line in readme.read_lines(encoding='utf-8'):
    print(line, end='')
print('-- EOF --')

with readme.parent as cwd:
    print(f'Current working directory: {cwd}')

# Change default hash algorithm from md5 to sha1
Path.default_hash = 'sha1'

print(f'File verification: {readme.verify("add3f48fded5e0829a8e3e025e44c2891542c58e")}')

Examples

  1. Read file line by line to stdout

    Path().read_lines()

  2. Write calculated hash to file

    Path().hexdigest()

  3. Read hashes from file for verification

    Path().verify() and contextmanager

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

pathlibutil-0.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

pathlibutil-0.1.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

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