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:

ROOT=/mnt/projects pathbase format --template '${ROOT}/{project}/{name}_v{version:03d}.txt' \
  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.2.tar.gz (14.7 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.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathbase-0.1.2.tar.gz
  • Upload date:
  • Size: 14.7 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.2.tar.gz
Algorithm Hash digest
SHA256 81d215b9b7f39c54409774016091abc314043b0d3f21b939eb95d096e9fae7df
MD5 be65a620a389f6777874794b5c28af34
BLAKE2b-256 11f3047e487fb33e79e912cb4d1c2c5747a0e8e7a0c54efde84624b551155458

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pathbase-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 45d05a985ca8b426c96d286bbde36c3182b76c528e40a51cdbc54175524fb955
MD5 ec9cd6359ec243ee87928dd9592b39de
BLAKE2b-256 d15a315c504e063e62e61372f1c625390472dc14647cf6d2767fb6b17fb12f25

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

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