fpathlib
A Python package for adding metadata to file paths.
fpathlib combines file paths with the metadata encoded in their names. It
does this with an f-string-like path pattern -- FPath -- whose
{variable} fields are captured out of every matching path on disk.
from fpathlib import expand
# Given files like data/tr1/output/0/job2.log, data/tr2/output/1/job0.log, ...
expanded = expand("data/tr{trajectory:d}/output/{replica:d}/job{job:d}.log")
for path in expanded:
print(path, path.metadata)
# data/tr1/output/0/job2.log {'trajectory': 1, 'replica': 0, 'job': 2}
# data/tr2/output/1/job0.log {'trajectory': 2, 'replica': 1, 'job': 0}
Combine the metadata for every matched path into a single table:
df = expanded.to_polars()
fpathlib.ext.polars goes a step further: it wraps polars's own
read_csv/scan_csv/read_txt/scan_txt so that an expandable path
pattern is accepted directly, and the resulting DataFrame or LazyFrame comes
back with the metadata already joined in.
import fpathlib.ext.polars as pl
df = pl.read_csv(
"data/tr{trajectory:d}/output/{replica:d}/job{job:d}.log",
has_header=False,
)
# df has columns "column_1", ..., plus "trajectory", "replica", "job"
Installation
pip install fpathlib
The fpathlib.ext.polars extension additionally requires polars, which
is not installed by fpathlib itself:
pip install polars
Documentation
Full API documentation is in docs/; build it locally with
scripts/docs.sh (requires the dev extras: pip install -e .[dev]).
Release files for fpathlib 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fpathlib-0.1.7.tar.gz | 19.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fpathlib-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.3 kB
Release files / fpathlib-0.1.7.tar.gz
| Download URL | fpathlib-0.1.7.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab8bac3b3adf327ebd9f9c3da6084efbf9098edfbfe621ae349c8b3fcbfa62f2
|
|
BLAKE2b-256 checksum How to use checksums |
615e7739f72038bdbf7d2193c6af782d05085ae8e6efabe014d44f4ed9f0b298
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / fpathlib-0.1.7-py3-none-any.whl
| Download URL | fpathlib-0.1.7-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14e5a45368e89114435ac2b7ab4e9b53d3b35de86749b0daa4c65b07f3d0b1ee
|
|
BLAKE2b-256 checksum How to use checksums |
bc609c4dc860d61a0e128471a7bacecf9a441a4f1a183b6c22ff0e3f1c9e12f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|