Skip to main content

Extract and aggregate YAML frontmatter from Markdown files into structured JSON

Project description

Matterify

Python 3.12+ License: MIT Status: Alpha PyPI

Extract and aggregate YAML frontmatter from Markdown files, with optional SHA-256 hashes and file statistics.

Quick Start

pip install matterify
matterify ./docs -o output.json

Installation

# Using uv (recommended)
uv add matterify

# Or with pip
pip install matterify

CLI Usage

matterify DIRECTORY [OPTIONS]

DIRECTORY must exist and is scanned recursively for .md and .markdown files.

Options:

  • --version - Show version information and exit
  • --debug - Enable debug logging
  • -o, --output PATH - Write JSON to file instead of stdout (if omitted, outputs to stdout)
  • --n-procs INT - Worker process count (default: auto-detect CPU cores)
  • -v, --verbose - Show progress and summary
  • -e, --exclude TEXT - Additional directories to exclude
  • --hash / --no-hash - Enable/disable SHA-256 hash computation
  • --stats / --no-stats - Enable/disable file statistics (size, modified time, access time)
  • --frontmatter / --no-frontmatter - Enable/disable YAML frontmatter extraction
  • --help - Show command help and exit

When --no-frontmatter is used, metadata fields files_with_frontmatter and files_without_frontmatter are null.

Examples:

# Output to stdout (JSON)
matterify ./docs

# Output to file
matterify ./docs -o output.json

# Verbose output
matterify ./docs --verbose

# Disable hashes and file stats
matterify ./docs --no-hash --no-stats

# Hash + stats only (skip YAML parsing)
matterify ./docs --no-frontmatter

# Exclude additional directories
matterify ./docs -e build -e .cache

# Full help
matterify --help

Python API

Public Functions

from pathlib import Path
from matterify import (
    scan_directory,
)

scan_directory

Scan directory and aggregate frontmatter using parallel workers. Returns an AggregatedResult dataclass.

from pathlib import Path
from matterify import scan_directory

result = scan_directory(Path("./docs"))

# AggregatedResult contains:
# - result.metadata: ScanMetadata with scan statistics
# - result.files: list of file entries with extraction results

# Access metadata
print(result.metadata.total_files)
print(result.metadata.files_with_frontmatter)
print(result.metadata.scan_duration_seconds)

# Access files
for entry in result.files:
    print(entry.file_path, entry.status)
    print(entry.stats.file_size if entry.stats else None)

Public Types

from matterify import (
    FileEntry,
    ScanMetadata,
    AggregatedResult,
)

# FileEntry: extracted frontmatter from a single file
entry: FileEntry

# ScanMetadata: summary statistics about a scan
metadata: ScanMetadata

# AggregatedResult: holds metadata and file entries
result: AggregatedResult

JSON Output Structure

When using CLI (stdout or --output), the payload has this shape:

{
  "metadata": {
    "source_directory": "/path/to/docs",
    "total_files": 10,
    "files_with_frontmatter": 8,
    "files_without_frontmatter": 2,
    "errors": 0,
    "scan_duration_seconds": 0.523,
    "avg_duration_per_file_ms": 52.3,
    "throughput_files_per_second": 19.1
  },
  "files": [
    {
      "file_path": "getting-started.md",
      "frontmatter": {
        "title": "Getting Started",
        "date": "2024-01-15",
        "tags": ["guide", "tutorial"]
      },
      "status": "ok",
      "error": null,
      "stats": {
        "file_size": 1234,
        "modified_time": "2024-01-15T10:30:00",
        "access_time": "2024-01-15T10:30:00"
      },
      "file_hash": "abc123..."
    }
  ]
}

status is either "ok" or "illegal".

Default Exclusions

The following directories are excluded from scanning by default:

  • .git
  • .obsidian
  • __pycache__
  • .venv
  • venv
  • node_modules
  • .mypy_cache
  • .pytest_cache
  • .ruff_cache

Use -e or --exclude to add custom exclusions.

Development

# Install with dev dependencies
uv sync --all-extras

# Run tests
uv run pytest

# Format and lint
uv run ruff format src/ tests/
uv run ruff check src/ tests/

# Type check
uv run mypy src/

License

MIT License - see LICENSE file for details.

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

matterify-0.3.0.tar.gz (58.0 kB view details)

Uploaded Source

Built Distribution

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

matterify-0.3.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file matterify-0.3.0.tar.gz.

File metadata

  • Download URL: matterify-0.3.0.tar.gz
  • Upload date:
  • Size: 58.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for matterify-0.3.0.tar.gz
Algorithm Hash digest
SHA256 806a219b9e59ed6d93df5b833851ec2853f87d48fd2a4661327cedd2bb53e133
MD5 22ce3e9262d76cfb89e114863ba8dbe7
BLAKE2b-256 623378dec454873f91333ec5abf50e0561f29c26cbb5bb41659e9f082ca8ac54

See more details on using hashes here.

Provenance

The following attestation bundles were made for matterify-0.3.0.tar.gz:

Publisher: publish.yml on chgroeling/matterify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file matterify-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: matterify-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for matterify-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 707da68e21bb505b471c17551f84f3ae437dc1deb456a088a8cc6f58844314c3
MD5 dff49401ac0f0c6e9da4e2584e8d3f11
BLAKE2b-256 bb3c6b189e536394921db82bf312deb7e40d6f8ea11811c83ed83a8193c4252f

See more details on using hashes here.

Provenance

The following attestation bundles were made for matterify-0.3.0-py3-none-any.whl:

Publisher: publish.yml on chgroeling/matterify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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