Skip to main content

Path Template

Project description

Path Template

Install

poetry add pathtmpl

Usage

import uuid
from pathlib import PurePath
from datetime import date as Date
from pathtmpl import Context, get_evaluated_path


path_tmpl = """
  /Tax/{{ year }}/{{ file_name }}
"""
context = Context(
    id=uuid.uuid4(),
    title="My Tax Declaration",
    file_name="elster_doc.pdf",
    category="Taxes",
    year=2025,
    month=12,
    day=11,
)

ev_path = get_evaluated_path(context, path_template=path_tmpl)
assert ev_path == PurePath("/Tax/2025/elster_doc.pdf")

Another example:

import uuid
from pathlib import PurePath
from pathtmpl import Context, get_evaluated_path


context = Context(
        file_name="receipt.pdf",
        title="Receipt from ALDI",
        id=uuid.uuid4(),
        year=2025,
        day=11,
        month=12,
        category="Grocery Receipts"
)
ev_path = get_evaluated_path(
    context,
    path_template="/{{ category }}/{{ year }}/{{ file_name }}",
)

expected_path = PurePath(
    "/Grocery Receipts/2025/receipt.pdf"
)
assert PurePath(ev_path) == expected_path

In its simplest form:

import uuid
from pathlib import PurePath
from pathtmpl import Context, get_evaluated_path


context = Context(
    title="coco",
    id=uuid.uuid4(),
    year=2025,
    day=11,
    month=12,
    file_name="invoice.pdf",
    category="Invoice"
)
ev_path = get_evaluated_path(context, path_template="/My Documents/Receipt/")

assert ev_path == "/My Documents/Receipt/"

Tests

poetry run pytest

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

pathtmpl-0.3.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

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

pathtmpl-0.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file pathtmpl-0.3.tar.gz.

File metadata

  • Download URL: pathtmpl-0.3.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure

File hashes

Hashes for pathtmpl-0.3.tar.gz
Algorithm Hash digest
SHA256 adda5088499c80aed4cafaefce30a5d730b8d04e9cf0a7a71306428dbdae6626
MD5 ae6f4003fea7c88582b6c793ce4cf7a9
BLAKE2b-256 866f19df9471aad27054a515f862a25b503cccc15e41af985134f3d7e94c759f

See more details on using hashes here.

File details

Details for the file pathtmpl-0.3-py3-none-any.whl.

File metadata

  • Download URL: pathtmpl-0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure

File hashes

Hashes for pathtmpl-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 889efe92aaeb3ab072837b73b9ede395444bc44abe94a66d8fae8b95c931eef3
MD5 e575862573f12ce890d730b6333af88e
BLAKE2b-256 8a3b635d887051518dd70422c68936c9e08daf5d89845463f09b5f9717c5dc51

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