Skip to main content

pathbase

PyPI CI License

pathbase is a lightweight, dependency-free Python library for bidirectional filesystem path templates.

Installation

pip install -U pathbase

Quick Example

Given a real filepath, pathbase can discover the matching template from environment-provided templates and extract the tokens:

This example assumes envstack is installed so ENVPATH is resolved before pathbase runs.

ENVPATH=./examples/vfx/ pathbase parse \
  '/mnt/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr'

Expected output:

{
  "fields": {
    "descriptor": "beauty",
    "ext": "exr",
    "frame": 1001,
    "sequence": "seq001",
    "shot": "shot010",
    "show": "bigbuckbunny",
    "step": "lighting",
    "task": "render",
    "version": 1
  },
  "template": "FILEPATH"
}

With envstack-managed templates, you can also emit the equivalent path for another platform:

ENVPATH=./examples/vfx/ pathbase parse --platform windows \
  '/mnt/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr'

Expected output:

{
  "fields": {
    "descriptor": "beauty",
    "ext": "exr",
    "frame": 1001,
    "sequence": "seq001",
    "shot": "shot010",
    "show": "bigbuckbunny",
    "step": "lighting",
    "task": "render",
    "version": 1
  },
  "platform_path": "D:/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr",
  "template": "FILEPATH"
}

If envstack is not installed, pathbase still supports direct environment variables and explicit mappings from Python.

You can also work with templates directly from Python:

from pathbase import Template

template = Template(
    "/mnt/projects/{show}/{sequence}/{shot}/{step}/"
    "{task}_{descriptor}_v{version:03d}.{frame:04d}.{ext}"
)

path = template.format(
    show="bigbuckbunny",
    sequence="seq001",
    shot="shot010",
    step="lighting",
    task="render",
    descriptor="beauty",
    version=1,
    frame=1001,
    ext="exr",
)

fields = template.parse(
    "/mnt/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr"
)

Pathbase supports:

  • Template.format(...) for path construction
  • Template.parse(path) for field extraction
  • automatic environment-based template discovery for CLI parsing and matching
  • typed numeric fields such as {version:03d} and {value:.2f}
  • repeated-field validation
  • mixed-separator parsing
  • embedded $VAR and ${VAR} expansion from os.environ or an explicit mapping
  • Template.from_env(...) as a convenience for environment-provided templates

Formatting output:

/mnt/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr

Parsing output:

{
    "show": "bigbuckbunny",
    "sequence": "seq001",
    "shot": "shot010",
    "step": "lighting",
    "task": "render",
    "descriptor": "beauty",
    "version": 1,
    "frame": 1001,
    "ext": "exr",
}

CLI

pathbase also includes a lightweight CLI:

pathbase format --template '${ROOT}/{project}/{name}_v{version:03d}.txt' \
  ROOT=/mnt/projects project=demo name=report version=1

ENVPATH=./examples/vfx/ pathbase parse \
  '/mnt/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr'

ENVPATH=./examples/vfx/ pathbase parse --platform windows \
  '/mnt/projects/bigbuckbunny/seq001/shot010/lighting/render_beauty_v001.1001.exr'

pathbase parse \
  '/mnt/projects/demo/report_v001.txt'

pathbase parse --template FILEPATH \
  '/mnt/projects/demo/report_v001.txt'

pathbase match '/mnt/projects/demo/report.txt'

Additional documentation lives in docs/index.md:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathbase-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

pathbase-0.1.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file pathbase-0.1.1.tar.gz.

File metadata

  • Download URL: pathbase-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for pathbase-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f843b05a26372e92e5948cd202c2a83dad6747269387fe2036e257eed5c8712d
MD5 85b5ac381c4a25c982e7b25bf016b223
BLAKE2b-256 017eef5d28a8507f8950ac054091085acf745c9361e4236dd54ceb7c50f70b69

See more details on using hashes here.

File details

Details for the file pathbase-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pathbase-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for pathbase-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53ce11fca9264723df3c943c3901f59a4387027a0f4b1cf31dd398f447cfe6ef
MD5 1f27d70404033e770fc0dd7733f5d6a4
BLAKE2b-256 4c9f1421baa0bf8be7e62695c13093947d852cfb999b36e7b6061f78e04341e0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

0.0.1

2 files

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