Skip to main content

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.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fpathlib 0.1.6
File Size Uploaded
fpathlib-0.1.6.tar.gz 19.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fpathlib 0.1.6
File Interpreter ABI Platform
fpathlib-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 33.1 kB

Release files / fpathlib-0.1.6.tar.gz

Download URL fpathlib-0.1.6.tar.gz
Size 19.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a7a3b1d99483a33a81db47de608a6e791a5afa155d062a5914fd9eee98878da1
BLAKE2b-256 checksum
How to use checksums
8943a6ada37518476c6d77c749e45acc3c1e3e78c5ae3a5e80a09985bce8779a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / fpathlib-0.1.6-py3-none-any.whl

Download URL fpathlib-0.1.6-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfa21d609b7c0cbbdfb0fa3167e0a74f1b8e1dd678421784a34c7bf4c395f402
BLAKE2b-256 checksum
How to use checksums
033685fbdab0900dc20017c21263dacc1402cf84cd6059f6c6542bdb2ad87467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page