Skip to main content

Input and output path checks. Simplifies handling of file/directory paths in scripts.

Project description

pathio

Path collection class for checking paths for input and output files/directories.

  • Initializing a collection (and later path additions) runs the suite of checks:
    • Duplication, existence (inputs), ... TODO add all checks
  • Printing/logging the collection provides a summary of the paths.
  • Paths are converted to pathlib.Path objects and missing directories can be created.
  • Can create missing output directories.

https://pypi.python.org/pypi/pathio/

Installation

Install from PyPI:

pip install pathio

Install from GitHub:

python -m pip install git+https://github.com/ludvigolsen/pathio

Main class/functions

Class/Function Description
IOPaths Collection of paths with built-in checks.
mk_dir Wrapper for creating directory if it doesn't exist.
rm_dir Wrapper for removing directory with relevant options.

Examples

Initialize the collection of path collections. Often the paths come from input arguments (like via argparse). Additional paths can be added later with set_path() or set_paths().

# Create path collection
paths = IOPaths(
    in_files={
        "in_file": "../dir1/dir2/john.csv",
        "stream_in": "-"
    },
    in_dirs={
        "in_dir": "../dir1/dir2/",
    },
    out_files={
        "out_file": "../dir1/dir2/output/no_john.csv"
    },
    out_dirs={
        "out_path": "../dir1/dir2/output/"
    }
)

Add additional path. Reruns checks to ensure consistency.

paths.set_path(
    name="in_file_2",
    path="../dir1/dir2/dennis.csv",
    collection="in_files"
)

Or set multiple at a time to avoid rerunning checks unnecessarily:

paths.set_paths(
    paths={
        "out_file_2": "../dir1/dir2/output/no_dennis.csv"
        "out_file_3": "../dir1/dir2/output/readme.txt"
    },
    collection="out_files"
)

Create the output directories that do not exist:

paths.mk_output_dirs(collection="out_dirs")

Get a path:

paths["in_file"]  # or
paths.get_path(name="in_file", as_str=False, raise_on_fail=True)

Remove file from disk:

paths.rm_file(name="in_file")

Update collection with another IOPaths collection. The sub collections are simple dicts, why this is just dict.update() on each sub collection.

paths.update(other=other_paths)

Find the combinations of keys and paths in the collections of this object that are not in the collections of another object:

paths.difference(other=other_paths)

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

pathio-0.1.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathio-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file pathio-0.1.0.tar.gz.

File metadata

  • Download URL: pathio-0.1.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.6 Darwin/23.6.0

File hashes

Hashes for pathio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d07c7e6b90e6dfc9d6fb5acb60680e298a037c08d28996aa01c3784337a34db
MD5 e26d5dc0f4937887642d4a3b198705b7
BLAKE2b-256 5c73b02b74623a2f30370cb1272d1d1e4f6890d05e8f7a79e81260cf605d11ee

See more details on using hashes here.

File details

Details for the file pathio-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pathio-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.6 Darwin/23.6.0

File hashes

Hashes for pathio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bad15816d2b929d10fb2452f7f3bbcbe35818108d886fc8069375b090a1ef7c5
MD5 7243e5db853a624f74380a66fa76c72c
BLAKE2b-256 ae8e6186f4f1725f731a268f11b982f3a849f4b5b4eaed8a5a11acdb328170b5

See more details on using hashes here.

Supported by

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