Skip to main content

Lightweight bidirectional filesystem path templates for Python.

Project description

pathbase

PyPI CI License

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

It is being extracted from the path-template functionality in envstack.path into a focused standalone package that stays intentionally small.

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:

export FILEPATH='{show}/{sequence}/{shot}/{step}/{task}_{descriptor}_v{version:03d}.{frame:04d}.{ext}'
pathbase parse '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"
}

The same flow also works well with envstack-managed templates. For example:

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

You can also work with templates directly from Python:

from pathbase import Template

template = Template(
    "{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(
    "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:

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 '{project}/{name}_v{version:03d}.txt' \
  project=demo name=report version=1

pathbase parse \
  'demo/report_v001.txt'

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

pathbase match 'demo/report.txt'

Additional documentation lives in docs/README.md:

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

pathbase-0.1.0.tar.gz (13.0 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.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathbase-0.1.0.tar.gz
  • Upload date:
  • Size: 13.0 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.0.tar.gz
Algorithm Hash digest
SHA256 e3213ab36bf96be639c22085a88df6e00730b0e3c2fc7b6cbfcb817da780b872
MD5 e91cec34153a6ad122258bb140333686
BLAKE2b-256 3dc942dcb6ec1fc998a99031321647f5bc9eceab48da74b3cc598ab40ac31138

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pathbase-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9b43172b8ace0d48f2530c13d771affa3c0242321df21a2e9cb30965d169b69
MD5 cf2f17e834a0711ef63cd1d976e2127c
BLAKE2b-256 9dae6bae2a8faa665848d98806cd3c2107f435c6ff2ef7ba7ef042ddfc628465

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