Skip to main content

Templated paths using t-strings

Project description

wend

PyPI version Python versions License pre-commit.ci status

A library for templated paths using Python t-strings (3.14+)

Installation

uv pip install wend

Requirements

  • Python 3.14+
  • Git (with sparse-checkout support)

About

For backstory read my blog about this package cog.spin.systems/future-paths!

The general idea is to use t-strings to house eagerly instantiated parameter objects which offer a form of deferred execution.

Usage

Following the examples in the blog post:

from pathlib import Path
from wend import Param, P, T, RelativePath

# Define parameters (late-bound)
root = Param("root")
dataset = Param("dataset")
idx = Param("idx")
total = Param("total")

# Build expressions - these don't touch the filesystem
data_dir = root / "data" / dataset
chunk_file = data_dir / T(t"chunk_{idx:04d}-of-{total:04d}.parquet")

# Inspect what's needed
print("Required params:", chunk_file.required_params())
# -> {'root', 'dataset', 'idx', 'total'}

# Resolve with bindings
path = chunk_file.resolve({
    "root": "/mnt/storage",
    "dataset": "train",
    "idx": 7,
    "total": 100,
})
print("Resolved:", path)
# -> /mnt/storage/data/train/chunk_0007-of-0100.parquet

# Constant folding happens at construction
folded = P("/home") / "user" / "data"
print("Folded type:", type(folded).__name__)
# -> LiteralExpr (not nested JoinExprs)

# Parent simplification
expr = root / "a" / "b"
print("Parent of join:", expr.parent)
# -> JoinExpr(ParamExpr, LiteralExpr("a")) -- the "b" is gone structurally

# Suffix chain collapse
double_suffix = (root / "file.txt").with_suffix(".tmp").with_suffix(".json")
print("Suffix chain:", double_suffix)
# -> WithSuffixExpr(base=JoinExpr(...), suffix='.json') -- .tmp is gone

# Connectivity: rebasing
config = RelativePath(
    base=root,
    relative=P("config") / "settings.yaml"
)
print("Config path:", config.resolve({"root": "/project"}))
# -> /project/config/settings.yaml

# Rebase to test environment
test_config = config.rebase(P("/tmp/test"))
print("Test config:", test_config.resolve({}))
# -> /tmp/test/config/settings.yaml

Contributing

Contributions are welcome! Please:

  1. Open an issue to discuss bugs or feature requests
  2. Fork the repo and submit a PR for changes
  3. Install dev dependencies with uv sync and run pre-commit install

License

MIT License - see LICENSE for details.

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

wend-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

wend-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wend-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.2 Linux/6.8.0-57-generic

File hashes

Hashes for wend-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce7c68617fa606f37fe06149e8ff5c1d7bdf826f0164967aa1bf40512715b106
MD5 d3ceade738d8c2f31ef91fbe76e9a769
BLAKE2b-256 22c087f6c3b34e2e765463843d27892e97f5f2e21ceed50b0070fd49aff75ee1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wend-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.6 CPython/3.14.2 Linux/6.8.0-57-generic

File hashes

Hashes for wend-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee1ba502515a64ce94ce4865a93e8ec44956b8b8383b673dcc60e6f2bcaaad94
MD5 5d5a665fd0b1667bee806ee7b7678406
BLAKE2b-256 0cab6c9203ee22e08fee6f9dd5b479e73b90032439aadf6eee355aa5cc43184a

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