Path Format
File format identification framework with heuristic evaluators and feature validators for Python.
Overview
vcti-path-format answers "what format is this file or folder, and how sure
are we?" Each format is a FormatDescriptor held in a FormatRegistry; the
descriptor's evaluator runs feature validators — magic bytes, extension, or
checks of your own — against a path. Validators are either gates, which
rule a format out when they fail, or evidence, which only lowers
confidence, and they are grouped into tiers of increasing cost so callers
can stop at cheap checks. FormatIdentifier evaluates a path against every
registered format and ranks the results on a five-level MatchConfidence
scale.
Installation
pip install "vcti-path-format>=2.1.2"
In pyproject.toml dependencies
dependencies = [
"vcti-path-format>=2.1.2",
]
Quick Start
from pathlib import Path
from vcti.pathformat.core import (
FormatDescriptor,
FormatIdentifier,
FormatRegistry,
HeuristicEvaluator,
MatchConfidence,
PathKind,
)
# Define a format descriptor with validators
hdf5_descriptor = FormatDescriptor(
id="hdf5-file",
name="HDF5 File",
evaluator=(
HeuristicEvaluator()
.check_path_kind(PathKind.FILE) # PRECONDITION: rules out directories
.check_magic_bytes(b"\x89HDF\r\n\x1a\n") # GATE
.check_extension([".h5", ".hdf5", ".he5"]) # EVIDENCE
),
attributes={"structure": "hdf5"},
)
# Register in a format registry
registry = FormatRegistry()
registry.register(hdf5_descriptor)
# Identify a file
identifier = FormatIdentifier(registry)
results = identifier.identify_file_format(Path("data.h5"))
for result in results:
print(f"{result.descriptor.name}: {result.confidence.name}")
# Get best match above a confidence threshold
best = identifier.get_best_match(
Path("data.h5"),
min_confidence=MatchConfidence.LIKELY,
)
Core Concepts
FormatDescriptor
Extends Descriptor[Evaluator] from vcti-plugin-catalog. Wraps an evaluator
with format metadata and attributes.
FormatRegistry
Extends Registry[FormatDescriptor]. Central catalog of known formats with
attribute-based filtering via registry.lookup.
FormatIdentifier
Evaluates a path against all (or filtered) registered formats and returns
results sorted by confidence, then by descriptor priority.
HeuristicEvaluator
Builder-pattern evaluator that runs feature validators and turns their results into a confidence:
from vcti.pathformat.core import HeuristicEvaluator, PathKind
evaluator = (
HeuristicEvaluator()
.check_path_kind(PathKind.FILE) # PRECONDITION
.check_magic_bytes(b"\x89PNG\r\n\x1a\n") # GATE
.check_extension([".png"]) # EVIDENCE
)
Each validator plays a role:
| Role | Failure | Success |
|---|---|---|
PRECONDITION |
Rules the format out | No evidence — the format merely applies (e.g. "is a file") |
GATE |
Rules the format out | Strong evidence of a match (e.g. the signature) |
EVIDENCE |
Lowers confidence | Raises confidence |
A validator that cannot obtain evidence — the file cannot be read — returns
an inconclusive result instead of a failure: an inconclusive
PRECONDITION or GATE gives CANT_EVALUATE, not CERTAINLY_NOT.
Confidence rules. A failed PRECONDITION or GATE gives CERTAINLY_NOT,
an inconclusive one CANT_EVALUATE, and either stops evaluation. Otherwise
the evaluator's confidence policy decides. The default policy:
- All passed + GATE present ->
DEFINITE - GATE passed, some EVIDENCE failed ->
LIKELY - All passed + no GATE ->
LIKELY - Some EVIDENCE failed, no GATE ->
UNLIKELY - No GATE and no conclusive EVIDENCE ->
CANT_EVALUATE
Feature Validators
| Validator | Default role | Tier | Checks |
|---|---|---|---|
PathKindValidator |
PRECONDITION | IDENTIFICATION | Path is a file, or a directory (check_path_kind) |
MagicBytesValidator |
GATE | IDENTIFICATION | File signature bytes (check_magic_bytes) |
AnyMagicBytesValidator |
GATE | IDENTIFICATION | Any of several (signature, position) pairs (check_any_magic_bytes) |
ExtensionValidator |
EVIDENCE | IDENTIFICATION | File extension (check_extension) |
Every descriptor is evaluated against every path, so a file format also
meets directories and a directory format meets files. check_path_kind()
rules those out before any other check reads the path; it looks at the
filesystem, not at descriptor attributes.
Custom validators implement the FeatureValidator protocol — no base class
needed. See docs/extending.md for a worked example and
for when to return a failed versus an inconclusive result.
Deciding What Counts
Which evidence matters is a property of the format, so the descriptor's author decides it:
role=on any builder method overrides a validator's default role — e.g. make an extension a GATE for a format it defines.policy=onHeuristicEvaluatorreplaces the default confidence policy with a function of the results.priority=onFormatDescriptorranks formats that reach the same confidence — e.g. CGNS above the plain HDF5 it is built on.
from vcti.pathformat.core import FormatDescriptor, HeuristicEvaluator, ValidatorRole
erf_descriptor = FormatDescriptor(
id="erfh5",
name="ERF HDF5",
evaluator=(
HeuristicEvaluator()
.check_magic_bytes(b"\x89HDF\r\n\x1a\n")
.check_extension([".erfh5"], role=ValidatorRole.GATE)
),
priority=10, # wins over a generic HDF5 descriptor when both match
)
Why the package leaves these choices to you is in docs/design.md; writing a policy is in docs/extending.md.
Validation Tiers
Control evaluation depth with max_tier:
| Tier | Cost | Examples |
|---|---|---|
IDENTIFICATION |
Cheap | Path kind, magic bytes, file extension |
STRUCTURE |
Medium | Schema validation, header parsing |
SEMANTIC |
Expensive | Content analysis, business logic |
from vcti.pathformat.core import ValidationTier
# Only run cheap checks
results = identifier.identify_file_format(path, max_tier=ValidationTier.IDENTIFICATION)
Evaluator Caching
Each HeuristicEvaluator caches its reports, keyed by the resolved path,
its modification time and size, and max_tier, so a changed file is
evaluated afresh. HeuristicEvaluator(cache_size=0) disables the cache,
evaluate(path, use_cache=False) bypasses it once, and cache_info() /
clear_cache() inspect and reset it. Sizing, the cases the key cannot see
(an edit inside an evaluated directory) and thread safety are in
docs/production-guide.md.
Pre-filtering with Rules
from vcti.lookup import Rule
# Only evaluate formats with structure="hdf5"
results = identifier.identify_file_format(
path,
rules=[Rule("structure", "==", "hdf5")],
)
Error Handling
A path that cannot be identified raises a standard exception, so one
except (ValueError, OSError) covers it:
| Exception | When |
|---|---|
FileNotFoundError (an OSError) |
Path does not exist; .filename holds the path |
UnsupportedPathError (a ValueError) |
Path is neither a regular file nor a directory, e.g. a socket or named pipe; .path holds the path |
An unreadable file is not an error either: MagicBytesValidator reports
it as inconclusive, so the formats it gates come out CANT_EVALUATE rather
than ruled out.
try:
results = identifier.identify_file_format(path)
except (ValueError, OSError) as e:
print(f"Cannot identify {path}: {e}")
A format whose evaluator fails does not stop the others. Its result is
CANT_EVALUATE, the error is attached as result.error, and a WARNING is
logged:
for result in identifier.identify_file_format(path):
if result.error is not None:
print(f"{result.descriptor.id} failed: {result.error}")
Pass strict=True to identify_file_format() or get_best_match() to
raise the error instead — useful in the tests of a descriptor package.
Errors from evaluation itself derive from EvaluatorError. All exception
classes are importable from vcti.pathformat.core:
| Exception | When |
|---|---|
EvaluatorError |
Base class for evaluator errors |
ValidationError |
A validator raised an unexpected exception; raised by FormatIdentifier only with strict=True |
InvalidValidatorError |
Invalid validator or arguments passed to a builder method |
PolicyError |
A confidence policy raised, or returned something other than (MatchConfidence, str); raised by FormatIdentifier only with strict=True |
Ecosystem
This package is the identification engine in a three-repo system:
| Package | Role |
|---|---|
| vcti-path-format | Framework: evaluators, validators, registry, identifier |
| vcti-path-format-attributes | Vocabulary: standardized attribute enums |
| vcti-path-format-descriptors | Built-in format definitions (HDF5, CAX, etc.) |
Dependencies
- vcti-plugin-catalog (>=2.0.0) — descriptor/registry framework
- vcti-lookup (>=2.0.0) — attribute-based filtering
Documentation
| If you want to… | Read |
|---|---|
| Get started using the package | Quick Start above |
| See practical, real-world usage | docs/patterns.md |
| Understand the architecture and design decisions | docs/design.md |
| Run it in a long-lived or multi-threaded service | docs/production-guide.md |
| See how the related path-format repositories fit together | docs/ecosystem.md |
| Navigate and understand the source | docs/source-guide.md |
| Add custom validators or evaluators | docs/extending.md |
Metadata
Release files for vcti-path-format 2.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vcti_path_format-2.1.2.tar.gz | 47.0 kB | With provenance | Details for vcti_path_format-2.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vcti_path_format-2.1.2-py3-none-any.whl | Python 3 | none | any | Details for vcti_path_format-2.1.2-py3-none-any.whl |
Total release size: 76.5 kB
Release files / vcti_path_format-2.1.2.tar.gz
| Download URL | vcti_path_format-2.1.2.tar.gz |
|---|---|
| Size | 47.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71fb4237deda2d8f06779d68a609909a421b1977e7e9cb71c54e6b2cb0e3b159
|
|
BLAKE2b-256 checksum How to use checksums |
1679cb3eb87598dddb44af530c62d0d6b96d8ab9473881b04512727309fd0e06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / vcti_path_format-2.1.2-py3-none-any.whl
| Download URL | vcti_path_format-2.1.2-py3-none-any.whl |
|---|---|
| Size | 29.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c2ccac959b98fb028005dc8c8f3a6b1e56294f0ed57b402644123a13141cb0a
|
|
BLAKE2b-256 checksum How to use checksums |
0dbbb898fcd6387f2bcfd6cada77e605f11656a1ee9788eb5e779c26ef9c7767
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for vcti-path-format 2.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for vcti_path_format-2.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.