Extended Pathlib
Project description
Superpathlib
Superpathlib offers Path objects with functionality extended from pathlib to maximize your productivity with a minimal amount of code.
Usage
from plib import Path
path = Path(filename)
1) Use properties to read & write path content in different formats
- text
- byte_content
- lines
- yaml
- json
- numpy
examples:
path.json = {key: value}
for line in path.lines:
if interesting(line):
process(line)
2) Use instance properties to get/set file metadata:
- get:
- size: filesize
- is_root: whether the owner of the file is a root user
- has_children: whether a path has children
- number_of_children: number of children in a folder
- filetype: content type of a file
- get & set:
- mtime: modified time
- tag: can be used for alternative ordering or metadata
examples:
path_new.mtime = path_old.mtime
if path.tag != skip_keyword and path.filetype == "video":
process(path)
3) Use class properties to access commonly used folders:
- docs
- assets
- ..
example:
names_path = Path.assets / 'names'
names = names_path.lines
4) Use additional functionality
- find(): recursively find all paths under a root that match a condition (extra options available for performance optimization)
- rmtree(): remove directory recursively
- copy_to(dest): copy content to dest
- copy_properties_to(dest): recursively copy path properties (mtime, tag) to all n-level children of dest
- tempfile(): create temporary file that can be used as context manager
- unpack(): extract archive(zip, tar, ..) file to desired folder
- pop_parent(): remove first parent from path in filesystem
- from_uri(): create path object from uri string
examples:
with Path.tempfile() as tmp:
do_work(logfile=tmp)
log = tmp.text
process(log)
condition = lambda p: (p / '.git').exists()
for git_path in root.find(condition):
process_git(git_path)
5) Enhance existing functionality
- Automatically create parents when writing files, creating new files, renaming files, ..
- Return default values when path does not exist (e.g. size = 0, lines=[])
6) Inherit from Path to define your own additional functionality:
example:
import plib
class Path(plib.Path):
def count_children(self):
return sum(1 for _ in self.iterdir())
This only works if you inherit from plib Path, not the standard library pathlib Path
Installation
pip install superpathlib
Install the packages corresponding with the properties you want to use
- e.g. PyYaml for yaml property
- Packages listed in requirements.txt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
superpathlib-1.1.0.tar.gz
(11.6 kB
view details)
Built Distribution
File details
Details for the file superpathlib-1.1.0.tar.gz
.
File metadata
- Download URL: superpathlib-1.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c27de3d479bbff3f4fa6ca89189651190a3896909dd76016a9caeaeaf55ef81 |
|
MD5 | b0dd46b92a56ac10a9f5817dd026d18a |
|
BLAKE2b-256 | 31ef58609caba343cc55d39c770614ba4d346e599092448d26bdd520d5b651bd |
File details
Details for the file superpathlib-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: superpathlib-1.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a2542113dfc4323786b82bc341585090b6874b64ce07a3abd6a4f303c2bd2ce |
|
MD5 | aec60debcff020792fd01f01a74caa3f |
|
BLAKE2b-256 | d49485cc3de7fce09d1296fa76244ccab06a4a17040444e2ceb72f58677e4026 |